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

目说的是一个分糖果的游戏,n个学生围成一圈,每个人手上有a[i]个糖果,每一轮游戏开始时,学生手中的糖果都是偶数,他们都把自己手中一半的糖果分给他右边的同学。分完后手中糖果数是奇数的,老师会给他一颗糖果。如果所有人手中的糖果数都一样 游戏结束。

输出总共进行了多少轮游戏 还有最后学生手中的糖果数。

 
 #include <iostream>
using namespace std;
int f(int a[],int n) //判断是否分配结束
{
int i;
for(i=;i<n-;i++)
if(a[i]!=a[i+])
return ;
return ;
}
int main()
{
int n; while(cin>>n&&n)
{
int a[],i,x=,y;
for(i=;i<n;i++)
cin>>a[i];
while(f(a,n))
{
x++;
y=a[n-]/;
for(i=n-;i>;i--)
{
a[i]=a[i]/+a[i-]/;
if(a[i]%)
a[i]++;
}
a[]=a[]/+y;
if(a[]%)
a[]++;
}
cout<<x<<" "<<a[]<<endl;
}
}

Candy Sharing Game(hdoj1034)的更多相关文章

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

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

  2. HDU 3269 P2P File Sharing System(模拟)(2009 Asia Ningbo Regional Contest)

    Problem Description Peer-to-peer(P2P) computing technology has been widely used on the Internet to e ...

  3. OpenStack 企业私有云的若干需求(3):多租户和租户间隔离(multi-tenancy and isolation)

    本系列会介绍OpenStack 企业私有云的几个需求: 自动扩展(Auto-scaling)支持 多租户和租户隔离 (multi-tenancy and tenancy isolation) 混合云( ...

  4. (译)iOS Code Signing: 解惑

    子龙山人 Learning,Sharing,Improving! (译)iOS Code Signing: 解惑 免责申明(必读!):本博客提供的所有教程的翻译原稿均来自于互联网,仅供学习交流之用,切 ...

  5. 第8章 传输层(1)_TCP/UDP协议的应用场景

    1. 传输层的两个协议 1.1 TCP和UDP协议的应用场景 (1)TCP协议:如果要传输的内容比较多,需要将发送的内容分成多个数据包发送.这就要求在传输层用TCP协议,在发送方和接收方建立连接,实现 ...

  6. 《NVM-Express-1_4-2019.06.10-Ratified》学习笔记(1)

    材料说明: 文档<NVM-Express-1_4-2019.06.10-Ratified.pdf>来自于NVMe网站:https://nvmexpress.org/ 笔记目的是学习NVMe ...

  7. 【树状数组(二叉索引树)】轻院热身—candy、NYOJ-116士兵杀敌(二)

    [概念] 转载连接:树状数组 讲的挺好. 这两题非常的相似,查询区间的累加和.更新结点.Add(x,d) 与 Query(L,R) 的操作 [题目链接:candy] 唉,也是现在才发现这题用了这个知识 ...

  8. Ajax:Cross-Origin Resource Sharing(转)

    实例:http://blog.csdn.net/hongweigg/article/details/39054403 通过XHR实现Ajax通信的一个主要限制,来源于跨域安全策略.默认情况下,XHR对 ...

  9. Cross-Origin Resource Sharing(CORS)详解,CORS详解,CORS原理分析

    Keywords CORS, 跨域,JS跨域调用,Ajax CORS 跨域,跨域详解,CORS跨域原理 Cross-Origin Resource Sharing详解 Cross-Origin Res ...

随机推荐

  1. ORACLE的客户端如何连接到数据库

    如何连接oracle数据库及故障解决办法   如何配置才能使客户端连到数据库:     要使一个客户端机器能连接oracle数据库,需要在客户端机器上安装oracle的客户端软件,唯一的例外就是jav ...

  2. [C++程序设计]对“&”和“*”运算符

    对“&”和“*”运算符再做些说明:(1) 如果已执行了“pointer_1=&a;”语句,请问&*pointer_1的含义是什么?“&”和“*”两个运算符的优先级别相同 ...

  3. 第二章IPC——IPC与开启多进程

    问题 一.IPC ①.什么是IPC  ②.为什么要有IPC 二.多进程 ①.如何开启多进程  ②.系统如何创建多进程 三.多进程引发的问题 问:私有进程(利用":+进程名")能否共 ...

  4. js判断数组和对象

    <script> var arr=new Array(); var obj={'1':2}; var num=11; function isType(obj){ if(obj instan ...

  5. 用php逐行读取文件

    做个备份年纪大了,都不愿意自己思考了 $str = file_get_contents($tmpfilename);//获得内容 $arr = explode("\n",$str) ...

  6. HDU 1026 Ignatius and the Princess I(BFS+优先队列)

    Ignatius and the Princess I Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &am ...

  7. JSTL: empty 可以减少很多繁冗的判空(转)

    ${empty student.name }Empty是判空为空返回的真不为空返回的是假 ${(empty student.name)? '空' : '非空'} <c:if test=" ...

  8. css3的loadding效果

    <!DOCTYPE html> <html> <head> <title>CSS3 loading效果</title> <meta c ...

  9. Effective Java单元测试TestNG - 就是爱Java

    TestNG是另一种单元测试的framework,与JUnit的类似,这次Mix将使用它来撰写测试程序,大部分所引用的class package都一样,只差在JUnit与TestNG的字样,可以直接用 ...

  10. CSS之清除浮动

    一.清除浮动的目的. 1.当一个父元素的高度不写或为auto时,而且这个父元素内又有浮动的子元素,那么这时候该父元素的高度将不会自动适应子元素的高度,也可以说高度是0px; 有如下代码: <di ...