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.

 

这道题的大意是N个开始都拿着偶数颗糖的小朋友围着老师坐,老师一吹哨子同时给自己右手边的同学自己一半的糖,结束后奇数颗糖的同学老师会给一颗糖补成偶数棵,直到大家手上的糖一样数目...问需要玩几次,以及最后糖的数量是多少?

 #include <iostream>
using namespace std;
#define Max 10000
int judge(int *stu,int len);
int main(void)
{
int student[Max];
int N;
int j=;
int i=;
int temp[Max];
int around=;
cin>>N;
while(N)
{
around=;
for(i=;i<N;i++)
cin>>student[i];
for(j=;;j++)
{ //所有的都看看有没有奇数
for(i=;i<N;i++)
{
student[i]=student[i]/;
temp[i]=student[i];
}
for(i=;i<N;i++)
{
student[i]+=temp[i-];
}
student[]+=temp[N-];
for(i=;i<N;i++)
{
if(student[i]%==)
student[i]+=;
}
around+=;
if(judge(student,N))
break; } cout<<around<<" "<<student[]<<endl;
cin>>N;
}
return ;
}
int judge(int *stu,int len)
{
int flag=;
for(int i=;i<len;i++)
{
if(stu[i-]==stu[i])
continue;
else {flag=;break;} }
return flag; }

杭电acm 1034题的更多相关文章

  1. 杭电acm 1076题

    水题,一个求闰年的题目,复习一下闰年的求法.... 1,如果能被4整除但不能被100整除的是闰年 2,能被400整除的是闰年 题目大意是:给定一个开始年份T以及一个正数N,要求求出从T开始,到了哪一年 ...

  2. 杭电acm 1037题

    本题应该是迄今为止最为简单的一道题,只有一组输入,输出也简单.... /****************************************** 杭电acm 1037题 已AC ***** ...

  3. 杭电acm 1038题

    本题比较简单,但是需要掌握几个小技巧,先上代码 /************************************* 杭电ACM 1038题,已AC ********************* ...

  4. 杭电acm 1049题

    一道水题..... 大意是一条1inch的虫子在一个n inch的盒子的底部,有足够的能够每一分钟往上爬u inch,但是需要休息一分钟,这期间会往下掉d inch,虫子爬到盒子口即认为结束.要求计算 ...

  5. 杭电acm 1033题

    Problem Description For products that are wrapped in small packings it is necessary that the sheet o ...

  6. 杭电ACM刷题(1):1002,A + B Problem II 标签: acmc语言 2017-05-07 15:35 139人阅读 评

    最近忙于考试复习,没有多少可供自己安排的时间,所以我利用复习之余的空闲时间去刷刷杭电acm的题目,也当对自己编程能力的锻炼吧. Problem Description I have a very si ...

  7. 杭电acm刷题顺序

    最近兴趣来了,闲暇之余,回顾大学期间刷过的杭电acm那些入门级别的题,以此巩固基础知识! 以下参考刷题顺序,避免入坑 原文传送门:https://blog.csdn.net/liuqiyao_01/a ...

  8. 杭电acm 1015题

    马上要找工作了,锻炼下自己的写程序能力,不多说,上代码 /********************杭电acm 1015 已AC 在这个程序里,使用穷举法来实现,但是输出顺序需要安装字典的最大 来输出 ...

  9. 杭电acm 1040题

    本题是一个非常简单的升序排序题目,但那时在做的时候把题目看错了,导致花费了大量的时间来检查为什么WA,最后发现题目看错了..... /********************************* ...

随机推荐

  1. RTMP & HLS

    一,直播云架构 2. RTMP 协议 RTMP(Real Time Messaging Protocol)是Adobe Systems公司为Flash播放器和服务器之间音频.视频和数据传输开发的开放协 ...

  2. UITableViewCell高度自适应的关键点

    iOS开发中对于UITableViewCell高度自适应的文章已经很多很多,但如果cell内容比较复杂,刚使用autolayout配置自使用时还是总不能一次性成功. KEY POINT 这里只说设置的 ...

  3. python3 内置常用函数系列一

    python3 内置了一系列的常用函数, python英文官方文档详细说明:点击查看, 为了方便查看,将内置常用的函数的记录一下来. Python3版本所有的内置函数: 1.abs() print(a ...

  4. 07 09&10

    0709: 排名还是不高,毕竟没切出来题. 第一题dalao: 要求你做一个三维数点,只回答最终有多少个点对的状态是完全小于(可比?)的.(n<=2000000) 特殊限制是三维都是随机排列. ...

  5. 改进地图的vo类

    现在的地图只是各帧特征点的集合.创建地图:局部,全局.局部:只相机位置附近的特征点,用来和当前帧匹配求解相机位置的.全局:不定位,回环检测和地图表达.重点或麻烦:维护局部地图的规模.为了实时,保证地图 ...

  6. HDU OJ 2159 FATE

    #include <stdio.h> #include <string.h> ][] ; ]; //»ñµÃ¾­Ñé ]; //»¨·ÑµÄÈÌÄÍ¶È int main() ...

  7. 对unidbgrid的单元格操作

    一.使某行某列单元格disabled: 1. UniStringGrid -> Options -> goEditing = true 2. UniStringGrid -> Ext ...

  8. SQLServer 一些有用的语句

    SET STATISTICS TIME ON 记录查询的相关数据 生成随机Guid SELECT NewID() 按照某一列排序并生成序号 select Row_Number() OVER (ORDE ...

  9. Mac 上Sublime Text 2配置lua环境

    1,首先下载最新版lua  然后解压到你想解压到的位置     http://www.lua.org/ftp/ 2,运行终端,cd  进入该文件夹src目录下. 3,在终端输入 make macosx ...

  10. angularjs 系列之$q和promise

    还是同一个项目,在项目中,发现多个controller之内有一个共同的服务器请求,当时只是不断的重复使用,如今,现在项目结束,代码开始走向了优化迭代的阶段: 首先,我的思路是把这个共同的请求,从con ...