hdoj 1034 Candy Sharing Game【基础题】&&【关键是理解题意】
来源:互联网 发布:中国gdp数据折线图 编辑:程序博客网 时间:2024/06/04 23:29
Candy Sharing Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4008 Accepted Submission(s): 2487
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.
代码:
#include<stdio.h>#include<string.h>#define N 10000int mb[N];int n;bool judge(){for(int i=0;i<n-1;++i) { if(mb[i]!=mb[i+1]) return false; } return true;}int main(){while(~scanf("%d",&n),n) { int cnt=0,i,s1,s2; for(i=0;i<n;++i) scanf("%d",&mb[i]); while(!judge()) { cnt++; s2=mb[0]; for(i=1;i<=n;++i) { s1=mb[i%n]; mb[i%n]=mb[i%n]/2+s2/2; s2=s1; } for(i=0;i<n;++i) if(mb[i]&1) mb[i]++; } printf("%d %d\n",cnt,mb[0]); }return 0;}
0 0
- hdoj 1034 Candy Sharing Game【基础题】&&【关键是理解题意】
- hdoj-1034-Candy Sharing Game
- hdoj 1034 Candy Sharing Game
- hdoj 1034 Candy Sharing Game
- hdoj 1034Candy Sharing Game
- HDOJ 1034 Candy Sharing Game
- HDOJ Candy Sharing Game
- hdoj 1034 Candy Sharing Game 【模拟】
- HDOJ 1034 Candy Sharing Game(模拟)
- HDOJ HDU 1034 Candy Sharing Game
- 1034:Candy Sharing Game
- 1034 Candy Sharing Game
- hdoj Candy Sharing Game 1034 (简单递推)
- hdoj 1034 Candy Sharing Game 【水模拟】【周赛】
- HDU 1034 Candy Sharing Game 模拟题
- hdu 1034 Candy Sharing Game
- hdu 1034 Candy Sharing Game
- HDU 1034 Candy Sharing Game
- Java语言基础(一)
- jQuery.extend 函数详解
- json 文件转换成 模型数据
- HDOJ 1950 Bridging signals(LIS nlogn)
- 两道面试题:2012年10月9号阿里巴巴笔试
- hdoj 1034 Candy Sharing Game【基础题】&&【关键是理解题意】
- poj 2151 01背包
- 如何在 Django 中使用 django-south, 实现数据迁移 (data migrations)
- 49. PHP 页面静态化(2)
- grep命令详解
- document.body.clientHeight = 0 ??
- 05 代码片格式化
- HTML编程图像处理
- HDOJ 4704 Sum(费马小定理+快速幂)