In a magical forest, there exists N bamboos that don't quite get cut down the way you would expect.
Originally, the height of the ith bamboo is equal to hi. In one move, you can push down a bamboo and decrease its height by one, but this move magically causes all the other bamboos to increase in height by one.
If you can do as many moves as you like, is it possible to make all the bamboos have the same height?
InputThe first line of input is T – the number of test cases.
The first line of each test case contains an integer N (1 ≤ N ≤ 105) - the number of bamboos.
The second line contains N space-separated integers hi (1 ≤ hi ≤ 105) - the original heights of the bamboos.
OutputFor each test case, output on a single line "yes” (without quotes), if you can make all the bamboos have the same height, and "no" otherwise.
Example2 3 2 4 2 2 1 2
yes
no
想了好久好久的规律啊
终于出来了
就是只要任意两个竹子的高度相差为偶数或0即可 代码自然就简单喽
#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
#include <map>
using namespace std;
///只要任意两数相差偶数就可以
int a[100005];
int main()
{
int t;
scanf("%d", &t);
while( t-- )
{
memset( a,0, sizeof( a ));
int n , i;
scanf("%d", &n);
for( i = 0; i<n; i++)
{
scanf("%d", &a[i]);
}
sort( a, a+n);
int f = 1;
for( i = 1; i<n; i++)
{
if( (a[i] - a[i-1])%2 != 0)
{
f = 0;
printf("no\n");
break;
}
}
if( f== 1)
{
printf("yes\n");
}
}
}