2017 ACM Arabella Collegiate Programming Contest Magical Bamboos
2018-01-09 20:11
1336 查看
Magical Bamboos
time limit per test
1.0 s
memory limit per test
256 MB
input
standard input
output
standard output
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
output
题意:给你n个数,每次将一个数减一,其他数加一,问经过几次操作后这n个数能否都相同
解题思路:将n个数排序后,相邻两个数的差为偶数即可
time limit per test
1.0 s
memory limit per test
256 MB
input
standard input
output
standard output
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
题意:给你n个数,每次将一个数减一,其他数加一,问经过几次操作后这n个数能否都相同
解题思路:将n个数排序后,相邻两个数的差为偶数即可
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <cmath> #include <map> #include <set> #include <stack> #include <queue> #include <vector> #include <bitset> #include <functional> using namespace std; #define LL long long const int INF = 0x3f3f3f3f; int n, h[100009]; int main() { int t; scanf("%d", &t); while (t--) { int flag = 1; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &h[i]); sort(h + 1, h + 1 + n); for (int i = 2; i <= n; i++) if ((h[i] - h[i - 1]) % 2 != 0) flag = 0; if(!flag) printf("no\n"); else printf("yes\n"); } return 0; }
相关文章推荐
- 2017 ACM Arabella Collegiate Programming Contest-L. All’s Wall That Ends Wall
- 2017 ACM Arabella Collegiate Programming Contest Snake Rana
- 2017 ACM Arabella Collegiate Programming Contest Competitive Seagulls
- 2017 ACM Arabella Collegiate Programming Contest Sherlock Bones
- 2017 ACM Arabella Collegiate Programming Contest Monkeying Around
- 2016-2017 ACM-ICPC, Egyptian Collegiate Programming Contest (ECPC 16) 题解
- Codeforces Gym 101608 - 2017 ACM Jordanian Collegiate Programming Contest
- 2017 ACM Jordanian Collegiate Programming Contest
- 2016-2017 ACM-ICPC, Egyptian Collegiate Programming Contest (ECPC 16)【solved:9 / 11】
- 【bfs && 反向建边】2016-2017 ACM-ICPC, Egyptian Collegiate Programming Contest (ECPC 16) Jumping
- Codeforces Gym 2015 ACM Arabella Collegiate Programming Contest(二月十日训练赛)
- ACM Arabella Collegiate Programming Contest 2015 H. Capital City 边连通分量
- 2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)
- 2017 ACM Amman Collegiate Programming Contest 题解
- GYM 2017 ACM Amman Collegiate Programming Contest
- Codeforces Gym 2015 ACM Arabella Collegiate Programming Contest
- 2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017) 部分题/平衡树/最小环/思路bfs
- 带权并查集:CF-2015 ACM Arabella Collegiate Programming Contest(F题)
- 2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)
- Codeforces Gym 2015 ACM Arabella Collegiate Programming Contest(二月十日训练赛)