Problem 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

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

 
Code:
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <ctype.h> using namespace std; int main()
{
int n;
while(scanf("%d",&n)&&n)
{
int i,a[n];
for(i=;i<n;i++)
scanf("%d",&a[i]); int t1,t2,flag,cnt=;
while(true)
{
a[]=t1=a[]/;
cnt++;
for(i=;i<n;i++)
{
a[i]=t2=a[i]/;
a[i]+=t1;
t1=t2; if(a[i]%)
a[i]++;
}
a[]+=t1;
if(a[]%)
a[]++; for(i=;i<n;i++)
if(a[i]!=a[])
{
flag=;
break;
}
else
flag=; if(flag)
break;
}
printf("%d %d\n",cnt,a[]);
}
return ;
}

HDU1034 Candy Sharing Game的更多相关文章

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

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

  2. POJ - 1666 Candy Sharing Game

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

  3. hdu 1034 Candy Sharing Game

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

  4. Candy Sharing Game(模拟搜索)

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

  5. M - Candy Sharing Game

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

  6. Candy Sharing Game(hdoj1034)

    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. sicily 1052. Candy Sharing Game

    Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description A number of students sit in a circle ...

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

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

随机推荐

  1. if 一元二次方程求根

    if 语句 - 只有当指定条件为 true 时,使用该语句来执行代码 if...else 语句 - 当条件为 true 时执行代码,当条件为 false 时执行其他代码 if...else if... ...

  2. Caused by: java.lang.RuntimeException: by java.lang.OutOfMemoryError: PermGen space(tomcat 启动时提示内存溢出)

    设置MaxPermSize大小TOMCAT_HOME/bin/catalina.bat 文件头加set JAVA_OPTS='-Xms512m -Xmx1024m -XX:MaxPermSize=51 ...

  3. test_markdown

    add modifications 非科学计数法显示数字 citation[^ref1] format bank% do not use scientific expression format lo ...

  4. linux 下载文件到本地磁盘的命令是什么

    linux下可以直接运行命令下载或上传文件1.检查并安装相应的包:yum install lrzsz2.使用 sz 文件名 现在相应的文件到本地磁盘.3.上传使用rz 选择相应文件即可.

  5. js禁止选中(网页复制)

    document.onselectstart=new Function("event.returnValue=false");//禁止选中(无法复制) document.oncon ...

  6. 微信小程序的开发环境搭建(Windows版本)

    前言: 小程序是指微信公众平台小程序,小程序可以帮助开发者快速的开发小程序,小程序可以在微信内被便捷地获取和传播:是一种不需要下载安装即可使用的应用小程序,和原有的三种公众号是并行的体系.2017年1 ...

  7. 关闭chrome浏览器的developer tools

    背景 Chrome使用过程中,很容易启动Chrome developer tools,一些误触如按到F12.CTRL+Shift+C等都会启动developer tools.对于不开发Web的人来说, ...

  8. pouchdb-find( pouchdb查询扩展插件 ,便于查询)

    pouchdb-find pouchdb-find 环境搭建 下载lib bower install pouchdb-find 引入js <script src="pouchdb.js ...

  9. Your password does not satisfy the current policy requirements

    创建用户,做测试想设置一个简单的密码.报错: 大概是MySQL5.7搞事情,默认安装了validate_password插件. mysql> SHOW VARIABLES LIKE 'valid ...

  10. 《javascript高级程序设计》笔记七

    第五章 引用类型(三) 今天首先说的就是Function类型.下面就是定义函数的两种方法,第一种使用函数声明语法定义,第二种使用函数表达式定义.这两种定义函数的方式几乎没有什么区别. function ...