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的更多相关文章

  1. POJ - 1666 Candy Sharing Game

    这道题只要英语单词都认得,阅读没有问题,就做得出来. POJ - 1666 Candy Sharing Game Time Limit: 1000MS Memory Limit: 10000KB 64 ...

  2. hdu 1034 Candy Sharing Game

    Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  3. Candy Sharing Game(模拟搜索)

    Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  4. M - Candy Sharing Game

    Description A number of students sit in a circle facing their teacher in the center. Each student in ...

  5. Candy Sharing Game(hdoj1034)

    Problem Description A number of students sit in a circle facing their teacher in the center. Each st ...

  6. HDU1034 Candy Sharing Game

    Problem Description A number of students sit in a circle facing their teacher in the center. Each st ...

  7. HDU 1034 Candy Sharing Game (模拟)

    题目链接 Problem Description A number of students sit in a circle facing their teacher in the center. Ea ...

  8. 九度OJ 1145:Candy Sharing Game(分享蜡烛游戏) (模拟)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:248 解决:194 题目描述: A number of students sit in a circle facing their teac ...

  9. HDU-1034 Candy Sharing Game 模拟问题(水题)

    题目链接:https://cn.vjudge.net/problem/HDU-1034 水题 代码 #include <cstdio> #include <algorithm> ...

随机推荐

  1. Trie字典树的学习及理解

    字典树详解见此 我这里学习时主要是看了李煜东的进阶指南里的讲解,以下是书中介绍的内容. Trie,又称字典树,是一种用于实现字符串快速检索的多叉树结构,Tire的每个节点都拥有若干个字符指针,若在插入 ...

  2. [SDOI2015]约数个数和 莫比乌斯反演

    ---题面--- 题解: 为什么SDOI这么喜欢莫比乌斯反演,,, 首先有一个结论$$d(ij) = \sum_{x|i}\sum_{y|j}[gcd(x, y) == 1]$$为什么呢?首先,可以看 ...

  3. 函数strcpy的实现

    strcpy函数的百科中给出了各种情况的详细说明,这里,仅给出一些注意事项: 1.strcpy的函数原型是: /* dest(destination)为目标字符串,src(source)为原字符串*/ ...

  4. POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理)

    POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理) 题意分析 不妨设日期为x,根据题意可以列出日期上的方程: 化简可得: 根据中国剩余定理求解即可. 代码总览 #include & ...

  5. 微信小程序 事件绑定 bind和catch 区别

    转自:https://blog.csdn.net/xiaoqiang_0719/article/details/79729592 本文以冒泡事件tap(手指触摸后马上离开,也就是点击事件)为例子来区别 ...

  6. 【P2602】【ZJOI2012】数字计数

    传送门 Description 给定两个正整数\(a\)和\(b\),求在\([a,b]\)中的所有整数中,每个数码(\(digit\))各出现了多少次. Input 两个正整数\(a,b\) Out ...

  7. JavaScript去除数组中的重复值

    用原型函数(prototype)可以定义一些很方便的自定义函数,实现各种自定义功能. Javascript 中的原型函数(prototype)的工作原理,在 javascript 中每次声明新函数的过 ...

  8. eclipse ide for java ee developers 开发环境搭建(J2EE) 【转载】

    使用eclipse真的有年头了,相信java程序员没有不知道它的,最近在给团队中新来的应届生做指导,专门讲解了一下Eclipse开发环境的搭建过程, 一是帮助他们尽快的熟悉IDE的使用,二也是保证团队 ...

  9. FileProvider记录下

    Mark下FileProvider,阿里巴巴Android开发手册有如下要求:[强制]应用间共享文件时,不要通过放宽文件系统权限的方式去实现,而应使用FileProvider. 知识点记录:1. An ...

  10. Java并发编程学习笔记

    Java编程思想,并发编程学习笔记. 一.基本的线程机制 1.定义任务:Runnable接口 线程可以驱动任务,因此需要一种描述任务的方式,这可以由Runnable接口来提供.要想定义任务,只需实现R ...