【 Gym

来源:互联网 发布:java项目经验描述 编辑:程序博客网 时间:2024/05/29 11:25

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.

Example
Input
2
3
2 4 2
2
1 2
Output
yes
no

题意 : 有一些竹子,可以选择其中的一颗让其长度减少 1,同时其他的竹子长度会加 1 ,问是否最后可以让所有的竹子长度相同

思路 :当所有的竹子长度全奇或全偶时可以,反之可以

AC代码:

#include<cstdio>#include<cmath>#include<map>#include<cstring>#include<algorithm>using namespace std;const int MAX = 1e5 + 10;typedef long long LL;int main(){    int T; scanf("%d",&T);    while(T--){        int n,l = 0,r = 0,a; scanf("%d",&n);        for(int i = 0 ; i< n; i++){            scanf("%d",&a);            if(a & 1) l++;            else r++;        }        if(!l || !r) puts("yes");        else puts("no");    }    return 0;}
原创粉丝点击