A. Yet Another Tetris Problem


A. Yet Another Tetris Problem


标签

  • 简单数学

简明题意

  • 给一个数列,每次可以给数列中的任何一个数+2.问能不能使得最终所有数相等

思路

  • 这个跟后面一场比赛的一题有点相似。Codeforces Round #630 (Div. 2)的E题。
  • 如果每次可以+2,那么只要序列的所有数的奇偶性相同即可使得最终全部相等。
  • 奇偶性相同,那么任意两个数的差都是偶数。所以也可以用差是否全部为偶数来判断。

注意事项


总结

  • 奇偶性一样,等价于两两之差为偶数

AC代码

#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring> 
#include<stack>
#include<map>
#include<queue>
#include<cstdio>	
#include<set>
#include<map>
#include<string>
using namespace std;

const int mod = 998244353;

void solve()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		int ji = 0, ou = 0;
		for (int i = 1; i <= n; i++)
		{
			int x;
			cin >> x;
			if (x & 1) ji++;
			else ou++;
		}
		if (ji && ou) cout << "NO" << endl;
		else cout << "YES" << endl;
	}
}
	
int main()
{
	//freopen("Testin.txt", "r", stdin);
	solve();
	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章