杭电1034 Candy Sharing Game
来源:互联网 发布:应用统计学与大数据 编辑:程序博客网 时间:2024/06/05 16:07
Candy Sharing Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4448 Accepted Submission(s): 2718
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.
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 8HintThe 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>#include<algorithm>using namespace std;int a[11000],i,j,k,l,m,n,cnm;int main(){while(scanf("%d",&n),n){for(i=0;i<n;i++)scanf("%d",&a[i]);int ans=0;while(1){cnm=a[n-1]/2;for(i=0;i<n;i++){int cnb=a[i]/2;a[i]=a[i]-cnb+cnm;cnm=cnb;}for(i=0;i<n;i++)if(a[i]%2)a[i]++;ans++;for(i=1;i<n;i++)if(a[i]!=a[i-1])break;if(i==n){printf("%d %d\n",ans,a[0]);break;}}}}
0 0
- 杭电 1034:Candy Sharing Game
- 杭电 HDU 1034 Candy Sharing Game
- 杭电-1034Candy Sharing Game(模拟)
- 杭电1034 Candy Sharing Game
- HDU杭电1034 Candy Sharing Game
- 【杭电oj】1034-Candy Sharing Game(水)
- 杭电1034(模拟法) 之 Candy Sharing Game
- 1034:Candy Sharing Game
- 1034 Candy Sharing Game
- 杭电HOJ1034 Candy Sharing Game 的一种解法
- 杭电oj(Java版)—— 1034 Candy Sharing Game
- hdu 1034 Candy Sharing Game
- hdu 1034 Candy Sharing Game
- HDU 1034 Candy Sharing Game
- hdoj-1034-Candy Sharing Game
- HDU 1034 Candy Sharing Game
- hdoj 1034 Candy Sharing Game
- hdu 1034 Candy Sharing Game
- iOS审核被拒 22.4 - Apps that enable illegal file sharing will be rejected
- linux的7种运行级别
- C# DataGridView
- APP接入微信支付步骤,及遇到的问题
- 【转载】python json
- 杭电1034 Candy Sharing Game
- Android的HelloWorld
- 提高Interface Builder高效工作的8个技巧
- Lucene入门实例
- 远程连接另一个主机上的MongoDB数据库服务器
- web自动化(5)----selenium运行JavaScript代码
- ZOJ 3623 Battle Ships 造战舰炸塔 动态规划 伪装较好的完全背包 ★★★
- csu1569: Wet Tiles
- 设置VMWARE通过桥接方式使用主机无线网卡上网