首页 技术 正文
技术 2022年11月15日
0 收藏 448 点赞 3,626 浏览 1789 个字

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

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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,564
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905