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

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. java分享第四天(循环)

    While循环: while(Boolean_expression){ //statements } 在执行时,如果布尔表达式的结果为真,则循环中的动作将被执行,这将继续下去,只要该表达式的结果为真 ...

  2. Redis入门笔记(二)-配置及运行

    转自: http://gly199.iteye.com/blog/1056424 1.redis基本参数 redis的配置文件中的常见参数如下: daemonize   是否以后台进程运行,默认为no ...

  3. Oracle函数解析

    一:大小写控制函数 lower()函数:(此函数将全部的大写字母都可以变为小写字母) upper()函数:(将输入的字符串变为大写字母) initcap()函数:(将每个字符串的首字母大写)  二:字 ...

  4. java二叉树的实现和遍历

    /* * Java实现二叉树 */ public class BinaryTree { int treeNode; BinaryTree leftTree; BinaryTree rightTree; ...

  5. HDU1892二维树状数组

    See you~ Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Su ...

  6. 允许浏览器跨域访问web服务端的解决方案

    今天和同事探讨了前后端如何真正实现隔离开发的问题,如果前端单独作为服务发布,势必会涉及到无法直接调用后端的接口的问题,因为浏览器是不允许跨域提交请求的. 所谓跨域访问,就是在浏览器窗口,和某个服务端通 ...

  7. Codeforces Round #350 (Div. 2) E 思维模拟

    给出一个合法的括号串 有LRD三种操作 LR分别是左右移动当前位置 且合法 D为删除这个括号和里面的所有 当删除完成后 位置向右移动 如果不能移动 就向左 比赛都是很久远的事情了 写这道题也是一时兴起 ...

  8. PHP 生成随机字符串与唯一字符串

    说明:生成随机字符串用到的方法有 mt_rand() 生成唯一字符串用到的方法有 md5(),uniqid(),microtime() 代码: <?php /* * 生成随机字符串 * @par ...

  9. 使用 JavaScript 实现链表

    代码: <!doctype html> <html lang="en"> <head> <meta charset="UTF-8 ...

  10. Java 操作符

    子系统的特点 instanceof 操作符 Animal类是Dog的直接父类,Creature类和Object类是Dog的间接父类,因此 Dog dog=new Dog(); System.out.p ...