【 Gym - 101350 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?

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;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值