Add Modulo 10

cf1714E.

思路在注释里,这是大佬的思路,相比之下我的一堆if太蠢了。所以思维题总是相不出来,或者想出来也要做好久,唉。

 

#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
using namespace std;
string s;
#define maxn 100
#define ll long long

//#define int long long
struct node {
	int a, b;
};
//1 2 4 8 6 2
//2 4 8 6 2
//3 6 2 4 8 6
//4 8 6 2 4
//5 0
//6 2 4 8 6
//7 4 8 6 2 4
//8 6 2 4 8
//9 8 6 2 4 8
//                 7  9
//                 |  |
//规律如图: 1->2->4->8->6<-3               
//              |________| 
// 
//               5<->0
//中间的循环2468正好是20,因此只要他们取余20结果一样,那就可以统一化成个位数是2的,这样取余20直接判断是否相等即可
//至于5,0特判即可,这个只要是有且不全是,那就肯定没法一样。
void solve()
{
	int ans = 0;
	int n;
	cin >> n;
	int a[maxn];
	int flag5 = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if (a[i] % 5 == 0)
			flag5++;
	}
	if (flag5 > 0 && flag5 < n)
	{
		cout << "NO" << endl;
		return;
	}
	for (int i = 1; i <= n; i++)
	{
		while (a[i] % 10 != 2 && a[i] % 10 != 0)
			a[i] += a[i] % 10;
	}

	if (flag5 == 0)
		for (int i = 1; i <= n; i++)
		{
			a[i] %= 20;
		}
	for (int i = 2; i <= n; i++)
		if (a[i] != a[i - 1])
		{
			cout << "NO" << endl;
			return;
		}
	cout << "YES" << endl;
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值