这道题只要英语单词都认得,阅读没有问题,就做得出来。

POJ - 1666 Candy Sharing Game

Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u

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

6

36

2

2

2

2

2

11

22

20

18

16

14

12

10

8

6

4

2

4

2

4

6

8

0

Sample Output

15 14

17 22

4 8

Hint

Notes: 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>
#include<math.h>
#include<stdlib.h> int n, stu[], give[]; int main()
{
while(scanf("%d", &n)) {
if(!n) break;
for(int i = ; i < n; i++) {
scanf("%d", &stu[i]);
}
int time = ;
while(true) {
bool flag = ;
for(int i = ; i < n; i++) {
if(i > && stu[i] != stu[]) {
flag = ;
break;
}
}
if(!flag) break; time++; for(int i = ; i < n; i++) {
give[i] = stu[i]/;
} for(int i = ; i < n; i++) {
stu[i] = give[i] + give[(i+)%n];
if(stu[i]%) {
stu[i]++;
}
} } printf("%d %d\n", time, stu[]); } return ;
}

POJ - 1666 Candy Sharing Game的更多相关文章

  1. hdu 1034 Candy Sharing Game

    Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  2. Candy Sharing Game(模拟搜索)

    Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  3. M - Candy Sharing Game

    Description A number of students sit in a circle facing their teacher in the center. Each student in ...

  4. Candy Sharing Game(hdoj1034)

    Problem Description A number of students sit in a circle facing their teacher in the center. Each st ...

  5. HDU1034 Candy Sharing Game

    Problem Description A number of students sit in a circle facing their teacher in the center. Each st ...

  6. HDU 1034 Candy Sharing Game (模拟)

    题目链接 Problem Description A number of students sit in a circle facing their teacher in the center. Ea ...

  7. sicily 1052. Candy Sharing Game

    Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description A number of students sit in a circle ...

  8. 九度OJ 1145:Candy Sharing Game(分享蜡烛游戏) (模拟)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:248 解决:194 题目描述: A number of students sit in a circle facing their teac ...

  9. POJ 1666

    #include<iostream> using namespace std; int main() { int num_stu; int i; ; do{ time=; cin>& ...

随机推荐

  1. C# Closure

    JavaScript Closure function f1(){ var n=999; return function(){ alert(n); // 999 return n; } } var a ...

  2. Qt 控件随窗口缩放

    在Qt的界面设计中,我们有时候希望窗口在最大化的时候,上面的控件也跟着缩放,那么我们就需要调整控件的SizePolicy属性,关于这个属性的讲解请参见我之前的博客Qt SizePolicy 属性,由于 ...

  3. jQuery对象和Dom对象

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. window.open()&&window.showmodaldialog()

    open 打开一个新窗口,并装载URL指定的文档,或装载一个空白文档,如果没提供URL的话. 适用于 窗口 语法 window = object.open([URL[,name[,features[, ...

  5. smarty 入门2(个人总结)

    1.下载安装: 2.拷贝libs文件夹到web文件夹: 3.引入smarty类文件   // include './libs/Smarty.class.php'; 4.配置smarty      // ...

  6. 除了白名单外的IP每秒最多处理 8 个请求 limit_conn_zone

    防止黑客知道你的源服务器真实IP进行并发攻击,通常只需要保护动态文件请求,�php. 添加文件 nginx/conf/limit/whiteip.conf 里面是你要忽略限制的 白名单 IP地址,通常 ...

  7. OPPO某某產品拍攝範圍嶄露頭角

    手機熱風暴再次襲來.oppo 開闢新道路.OPPO爆料N3採用旋智能轉攝像頭!很青睞一些愛拍照的我們.愛攝影的我們.覺的代攝影機麻煩.OPPo同樣給你全新的視野新加坡自由行. 隨著OPPO N3發布會 ...

  8. iPhone6手機產品提交了進網申請

    近期,海外投資蘋果公司為iPhone6手機產品提交了進網申請,經電信設備進網檢測機構測試和我部審查,相關產品滿足進網管理要求.根據<電信條例>有關規定,我部依法定程式在法定時限內為蘋果公司 ...

  9. A trip through the Graphics Pipeline 2011_10_Geometry Shaders

    Welcome back.     Last time, we dove into bottom end of the pixel pipeline. This time, we’ll switch ...

  10. Java Debug调试简单方法--static使用

    Public class Debug { public Debug() { } static void debugPrint(String src) { //System.out.print(src) ...