Description
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?
Input
The 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.
Output
For 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.
Sample Input
2 3 2 4 2 2 1 2
Sample Output
yes no
题解:砍竹子,一个竹子砍1,其他的加1,找规律,当有两个竹子相差奇数时,一定不能使其都等长。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn = 1e5+5;
const double Pi = acos(-1);
const int INF = 0x3f3f3f3f;
typedef long long ll;
int main()
{
int t,a[maxn];
scanf("%d",&t);
while(t--)
{
int n,flag=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
for(int i=n-1;i>0;i--)
{
if((a[i]-a[i-1])%2!=0)
{
flag=1;
break;
}
}
if(!flag)
printf("yes\n");
else
printf("no\n");
}
return 0;
}