D. Magical Bamboos
题目描述
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?
输入
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.
输出
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.
样例
inputCopy
2
3
2 4 2
2
1 2
outputCopy
yes
no
题意
简单分析一下我们就会发现明显这个只要所有数的奇偶性质一样就可以了
AC代码
#include <cstdio>
#include <cstring>
#include<algorithm>
using namespace std;
bool cmp(int a,int b){
return a>b;
}
const int MAXN =1e5+10;
int arr[MAXN];
int main(){
int t;
scanf("%d",&t);
while (t--){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&arr[i]);
sort(arr,arr+n,cmp);
int flag=1;
for(int i=1;i<n;i++){
if((arr[i]-arr[i-1])&1) {
flag=0;break;
}
}
if(flag) puts("yes");
else puts("no");
}
return 0;