hdoj-1034-Candy Sharing Game

来源:互联网 发布:上网流量控制软件 编辑:程序博客网 时间:2024/06/04 18:40

Candy Sharing Game

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3812 Accepted Submission(s): 2377


Problem Description
A number of students sit in a circle facing their teacher in the center. Each student initially has an even number of pieces of candy. When the teacher blows a whistle, each student simultaneously gives half of his or her candy to the neighbor on the right. Any student, who ends up with an odd number of pieces of candy, is given another piece by the teacher. The game ends when all students have the same number of pieces of candy.
Write a program which determines the number of times the teacher blows the whistle and the final number of pieces of candy for each student from the amount of candy each child starts with.

Input
The input may describe more than one game. For each game, the input begins with the number N of students, followed by N (even) candy counts for the children counter-clockwise around the circle. The input ends with a student count of 0. Each input number is on a line by itself.

Output
For each game, output the number of rounds of the game followed by the amount of candy each child ends up with, both on one line.

Sample Input
6362222211222018161412108642424680

Sample Output
15 1417 224 8
Hint
The game ends in a finite number of steps because:1. The maximum candy count can never increase.2. The minimum candy count can never decrease.3. No one with more than the minimum amount will ever decrease to the minimum.4. If the maximum and minimum candy count are not the same, at least one student with the minimum amount must have their count increase.

Source
Greater New York 2003

#include<stdio.h>#include<string.h>int a[10000];int n;bool judge(){for(int i=0;i<n-1;++i){if(a[i]!=a[i+1]) return false;}return true;}int main(){while(~scanf("%d",&n),n){    int ncas=0,i,t1,t2;for(i=0;i<n;++i) scanf("%d",&a[i]);while(!judge()){ncas++;    t2=a[0];for(i=1;i<=n;++i){t1=a[i%n];a[i%n]=a[i%n]/2+t2/2;t2=t1;}for(i=0;i<n;++i)  if(a[i]&1) a[i]++;}printf("%d %d\n",ncas,a[0]);}return 0;}

We have carefully selected several similar problems for you:1035 1031 1037 1038 1015

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 客户端提示初始化控件失败怎么办 刺客信条兄弟会存档损坏怎么办 百度不小心点赞怎么办 c盘空间不够了怎么办 百度云打开压缩文件失败怎么办 电脑只有一个c盘怎么办 u盘文件删不了怎么办 在电脑上照片打不开乱码怎么办 win7电脑登录密码忘记了怎么办 三洋电视应用商店打不开怎么办 中兴手机应用商店打不开怎么办 绝地求生与服务器失去连接怎么办 战地4载入不进去怎么办 电脑软件无法找到入口怎么办 ipad的按键坏了怎么办 更新ios12软件闪退怎么办 设置虚拟服务器输入不了数字怎么办 玩客云自动备份设备连接失败怎么办 3dmax文件打开失败怎么办 夏天吹空调嘴歪怎么办 燃气热水器温度调节拧不动怎么办 能率热水器震动声大怎么办 车底盘磕了漏油怎么办 法士特变速箱的随动阀漏气了怎么办 大灯随动afs失灵怎么办 2017款迈腾大灯随动故障怎么办 微信gps信号不好怎么办 苹果6s定位不准怎么办 电脑不读取u盘怎么办 注塑机上的料烤坨了怎么办 智能锁电机坏了怎么办 注塑机加热嘴内扣突了怎么办 tpu粘在螺杆上怎么办 注塑机锁模时会有射退动作怎么办 电动车刹车油泵不打油怎么办 cad转pdf颜色浅怎么办 松下多功能传真一体机卡纸怎么办 无刷电机坏了怎么办 6kv高压电机绝缘不合格怎么办? 400t油压机下降太慢怎么办 无法连线到服务器1~1怎么办?