【Gym - 101350 D - Magical Bamboos 】& gcd
2017-08-21 21:03
423 查看
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 个人要吃的食物量,问选者什么型号的盘子(型号 o 的盘子可以盛的食物的量为 o),每个人盛的食物的量恰好等于每个要吃的食物的量,满足条件的情况下 o 尽可能的大
思路 : gcd,因为 1 的时满足条件
AC代码:
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 个人要吃的食物量,问选者什么型号的盘子(型号 o 的盘子可以盛的食物的量为 o),每个人盛的食物的量恰好等于每个要吃的食物的量,满足条件的情况下 o 尽可能的大
思路 : gcd,因为 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 gcd(int a,int b){ return a % b == 0 ? b : gcd(b,a % b); } int main() { int T; scanf("%d",&T); while(T--){ int n,a,o = -1; scanf("%d",&n); LL ans = 0; for(int i = 0 ; i< n; i++){ scanf("%d",&a); o = o == -1 ? a : gcd(a,o); ans += a; } printf("%lld %d\n",ans,o); } return 0; }
相关文章推荐
- 【 Gym - 101350 D - Magical Bamboos】
- 【Gym - 101350 E - Competitive Seagulls】 & 博弈
- 【Gym - 101350A. Sherlock Bones】 & 思维
- 最大公约数gcd&最小公倍数lcm
- 解题报告 之 SOJ2106 GCD & LCM Inverse
- ZOJ 1577 - GCD & LCM
- Gym 100342J & Gym 100345H (bitset在图论题的应用)
- <模板>(Miller-Rabin和Pollard_rho算法)poj 2429 GCD & LCM Inverse (数论)
- 扩展gcd&模线性方程
- POJ 2429 GCD & LCM Inverse
- GCD 学习(三)Main&Global Dispatch Queue
- 让人头疼的ios&nbsp;8——GCDAsynSoc…
- zoj 1577 GCD & LCM
- Gym 100971B 水&愚
- 杭电2504 gcd的用法,(a%b==0)&&(i%b==0)&&(i!=b)&&(gcd(a,i)==b)可以只写为(i!=b)&&(gcd(a,i)==b))
- 笔试算法题(34):从数字序列中寻找仅出现一次的数字 & 最大公约数(GCD)问题
- GCD nyoj1007(欧拉函数运用&&数论入门)
- POJ2429_GCD & LCM Inverse【Miller Rabin素数测试】【Pollar Rho整数分解】
- AOJ-AHU-OJ-401 Fibonacci & GCD
- GYM 101550 && CSUOJ 2017 Highest Tower 思维 模型转换