POJ - 1666 Candy Sharing Game
这道题只要英语单词都认得,阅读没有问题,就做得出来。
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的更多相关文章
- hdu 1034 Candy Sharing Game
Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- Candy Sharing Game(模拟搜索)
Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- M - Candy Sharing Game
Description A number of students sit in a circle facing their teacher in the center. Each student in ...
- Candy Sharing Game(hdoj1034)
Problem Description A number of students sit in a circle facing their teacher in the center. Each st ...
- HDU1034 Candy Sharing Game
Problem Description A number of students sit in a circle facing their teacher in the center. Each st ...
- HDU 1034 Candy Sharing Game (模拟)
题目链接 Problem Description A number of students sit in a circle facing their teacher in the center. Ea ...
- sicily 1052. Candy Sharing Game
Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description A number of students sit in a circle ...
- 九度OJ 1145:Candy Sharing Game(分享蜡烛游戏) (模拟)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:248 解决:194 题目描述: A number of students sit in a circle facing their teac ...
- POJ 1666
#include<iostream> using namespace std; int main() { int num_stu; int i; ; do{ time=; cin>& ...
随机推荐
- The Bus Driver Problem
题目连接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=90648#problem/G 题意: 给每位司机分配一个白天和晚上的行车路线, ...
- Linux_系统管理命令(工作中经常使用到的)
查看网络配置信息 ifconfig 查看系统资源信息(类似win系统资源管理器) top (ps: load average 负载 Task 进程 Cpus/Mem swap 交换分区 类似wi ...
- Jquery超简单遮罩层实现代码
看了很多代码,下面跟大家分享一下我认为最简单的遮罩层实现方式: 1.样式如下设置: CSS代码: <style type="text/css"> .mask { pos ...
- sprin加载顺序
spring加载有个比较有意思的问题,这里片很不错的文章 http://guoliangqi.iteye.com/blog/632697
- JS验证只允许输入数字
1.文本框只能输入数字代码(小数点也不能输入)<input onkeyup="this.value=this.value.replace(/\D/g,'')" onafter ...
- phpexcel的写操作将数据库中的数据导入到excel中
这个版本据说是可以支持excel2007,但是我使用2007编辑的xlsx是无法获得该库的支持.于是乎我就将它转化为2003.感觉支持地很好. 下面介绍一下具体的使用: require_once('. ...
- BizTalk开发系列(三十八)微软BizTalk Server定价和许可[解读]
做BizTalk的项目一段时间了,但是对BizTalk的价格和许可还不是很了解.给客户设计解决方案时大部分产品都是直接按照企业版的功能来设计,很 少考虑到价格和许可方面的因素,以为这个不是我们的事情或 ...
- EL表达式与JSTL
内容包括 EL表达式 EL函数库 JSTL 核心标签库 格式化标签库 SQL标签库 XML标签库 自定义标签库 EL表达式 EL是Expression Language的是缩写,是JSP页面编写的一种 ...
- A trip through the Graphics Pipeline 2011_06_(Triangle) rasterization and setup
Welcome back. This time we’re actually gonna see triangles being rasterized – finally! But before we ...
- C 到C++的升级
C++所有的变量都可以在需要使用时再定义. C语言中的变量都必须在作用域开始的位置定义. register 关键字请求编译器将局部变量存储于寄存器中 在C语言无法获取register 变量的地址 在C ...