sicily 1052. Candy Sharing Game
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
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
- 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
- #include <iostream>
- #include <vector>
- using namespace std;
- int main(int argc, char const *argv[])
- {
- int stuNum;
- vector<int> stuCandy;
- while (cin >> stuNum && stuNum != ) {
- stuCandy.resize(stuNum);
- for (int i = ; i != stuNum; ++i)
- cin >> stuCandy[i];
- int roundNum = ;
- while (++roundNum) {
- int firstCandy = stuCandy[];
- int i;
- for (i = ; i != stuNum - ; ++i) {
- stuCandy[i] -= (stuCandy[i] / );
- stuCandy[i] += (stuCandy[i + ] / );
- if (stuCandy[i] % != )
- stuCandy[i] += ;
- }
- stuCandy[i] -= (stuCandy[i] / );
- stuCandy[i] += (firstCandy / );
- if (stuCandy[i] % != )
- stuCandy[i] += ;
- for (i = ; i != stuNum - ; ++i) {
- if (stuCandy[i] != stuCandy[i + ])
- break;
- }
- if (i == stuNum - )
- break;
- }
- cout << roundNum << " " << stuCandy[] << endl;
- }
- return ;
- }
sicily 1052. Candy Sharing Game的更多相关文章
- POJ - 1666 Candy Sharing Game
这道题只要英语单词都认得,阅读没有问题,就做得出来. POJ - 1666 Candy Sharing Game Time Limit: 1000MS Memory Limit: 10000KB 64 ...
- 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 ...
- 九度OJ 1145:Candy Sharing Game(分享蜡烛游戏) (模拟)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:248 解决:194 题目描述: A number of students sit in a circle facing their teac ...
- HDU-1034 Candy Sharing Game 模拟问题(水题)
题目链接:https://cn.vjudge.net/problem/HDU-1034 水题 代码 #include <cstdio> #include <algorithm> ...
随机推荐
- Dom选择器以及内容文本操作
1. DOM:文档对象模型.把整个HTML当做大的对象.每一个标签认为是一个对象.(每一个个体就是一个对象) 2. 查找: 直接查找 var obj=document.getElementById(& ...
- JS内存空间详细图解
JS内存空间详细图解 变量对象与堆内存 var a = 20; var b = 'abc'; var c = true; var d = { m: 20 } 因为JavaScript具有自动垃圾回收机 ...
- CentOS httpd服务(Apache)
1.从ISO镜像安装,Apache 服务的软件包名称为 httpd #检查源配置[root@localhost media]# cat /etc/yum.repos.d/CentOS-Media.re ...
- [POI2014]FAR-FarmCraft 树形DP + 贪心思想
(感觉洛谷上题面那一小段中文根本看不懂啊,好多条件都没讲,直接就是安装也要一个时间啊,,,明明不止啊!还好有百度翻译......) 题意:一棵树,一开始在1号节点(root),边权都为1,每个点有点权 ...
- BZOJ1053:[HAOI2007]反素数——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1053 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4.如果某个正整数x满 ...
- SpringMVC配置详解(转)
要想灵活运用Spring MVC来应对大多数的Web开发,就必须要掌握它的配置及原理. 一.Spring MVC环境搭建:(Spring 2.5.6 + Hibernate 3.2.0) 1. jar ...
- P2075 [NOIP2012T5]借教室 区间更新+二分查找
P2075 [NOIP2012T5]借教室 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 noip2012-tg 描述 在大学期间,经常需要租借教室.大到院 ...
- js获取当前页面的参数,带完善~~~
let url = window.location.href; let id = url.slice(url.indexOf('?') + 4);
- 实体框架(Entity Framework)快速入门
实体 框架 (Entity Framework )简介 实体框架Entity Framework 是 ADO .NET 中的一组支持 开发 面向数据的软件应用程序的技术.是微软的一个ORM框架. OR ...
- [技巧篇]02.关于MyBatis存取图片到MySQL数据Blob字段