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. iOS-UI控件概述

    IBAction和IBOutlet,UIView 1 @interface ViewController : UIViewController 2 3 @property(nonatomic, wea ...

  2. 《转》vue-cli的webpack模板项目配置文件注释

    一.文件结构 本文主要分析开发(dev)和构建(build)两个过程涉及到的文件,故下面文件结构仅列出相应的内容. ├─build │ ├─build.js │ ├─check-versions.js ...

  3. hdu 1142 A Walk Through the Forest (最短路径)

    A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  4. [AHOI2009]最小割 最小割可行边&必须边

    ~~~题面~~~ 题解: 做这题的时候才知道有最小割可行边和必须边这种东西..... 1,最小割可行边, 意思就是最小割中可能出现的边. 充要条件: 1,满流 2,在残余网络中找不到x ---> ...

  5. 剑桥offer系列(1~10)

    1.题目描述 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. 思路:从左下开始, ...

  6. Linq改进

    原代码: foreach (var item in pageData) { list.Add(new tn_Manager { UserName = item.UserName, IsAudit = ...

  7. 2115: [Wc2011] Xor (线性基+dfs)

    2115: [Wc2011] Xor Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 5714  Solved: 2420 题目链接:https://w ...

  8. HDU4738:Caocao's Bridges(求桥)

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. Ubuntu12.04 安装LAMP及phpmyadmin

    1.安装 Apache apt-get install apache2 2.安装 PHP5 apt-get install php5 libapache2-mod-php5 3.安装 MySQL ap ...

  10. 汕头市队赛SRM 20 T2不净的圣杯

    不净的圣杯 SRM 20 背景 作为一张BUG级别的卡,官方打算把它修改得人畜无害一些…… 虽然名字还没想好,但是能力大概是对敌方所有单位造成d点伤害,d为自己牌组中所有卡的编号的最大公约数.这无疑是 ...