【 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;}
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Shell脚本中的字符串测试
- anaconda与pip install, sudo pip install
- HDU 6050 Funny Function(矩阵快速幂或公式)
- Java选项卡的使用
- LA 3485 自适应Simpson积分 解题报告
- 【 Gym
- sigaction函数
- 线段树和树状数组的认识与总结
- SpringMVC基于xml配置文件的开发
- 简单C语言实现由1-N组成一个N位各位不重复的数字,该数字前M个数字组成的数可以被M整除
- codevs 3327 选择数字 单调队列优化DP
- MapReduce的输入格式---KeyValueTextInputFormat---源码分析
- tar.gz00 xxx.tar.gz01 xxx.tar.gz02……解压
- 【HPU-2016校赛-D】Ou à