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

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. XML参考 :XmlReader 详解、实例

    XML参考 :XmlReader 详解.实例-- 详解 转:http://www.cnblogs.com/Dlonghow/archive/2008/07/28/1252191.html XML参考 ...

  2. PHP的学习--cookie和session--来自copy_02

    PHP的学习--cookie和session   最近读了一点<PHP核心技术与最佳实践>,看了cookie和session,有所收获,结合之前的认识参考了几篇博客,总结一下-- 1. P ...

  3. Working with C# dictionary

    Check dictionary value if it's empty dictionary.ElementAt(i).Value == DBNull.Value Check string valu ...

  4. 9x9乘法表输出[Java]

    笔试,9x9乘法表输出的问题,看似简单,回来把当时写的结果输入一遍后发现,并没有想象中的“完美”.把改写的pos在此,警示...不要忘记任何细节. public class NXN { public ...

  5. php——用for循环打印半金字塔、金字塔、正方形、倒金字塔、菱形、空心图形等

    1.半金字塔 $n=5; //控制层数 for($i=1;$i<=$n;$i++){ //控制每层的 “*” 数 for($j=1;$j<=$i;$j++){ echo  "*& ...

  6. 有效的PhoneGap CSS: WebKit Tap Highlight Color

    原文链接:文章1:http://phonegap-tips.com/articles/essential-phonegap-css-webkit-tap-highlight-color.html(此文 ...

  7. IOS彩票第二天设置界面(2)

    *********代码的抽取ILBaseTableViewController.h #import <UIKit/UIKit.h> @interface ILBaseTableViewCo ...

  8. Linux内存管理基本概念

    1. 基本概念 1.1 地址 (1)逻辑地址:指由程序产生的与段相关的偏移地址部分.在C语言指针中,读取指针变量本身值(&操作),实际上这个值就是逻辑地址,它是相对于你当前进程数据段的地址.( ...

  9. DS实验题 PlayGame Kruskal(UnionFindSet)

    题目: 思路: 有两种做法,一种是Prim算法,另外一种则是我所使用的Kruskal算法,Kruskal的算法实现可以参考:最小生成树-Prim算法和Kruskal算法,讲的已经是十分清楚了. 具体算 ...

  10. 20145224&20145238《信息安全系统设计基础》实验一 开发环境的熟悉

    20145224陈颢文20145238荆玉茗 <信息安全系统设计基础>第一次实验报告 课程:信息安全系统设计基础 班级: 1452 姓名:荆玉茗 陈颢文 学号:20145238 20145 ...