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. Html 编码 queryUrl = encodeURI(queryUrl);

    Html  编码 queryUrl = encodeURI(queryUrl);

  2. 编译安装httpd

    一.安装前的说明: httpd依赖于apr和apr-util所以在安装httpd之前要把这些东西都安装上去. 事先安装的依赖: yum -y install gcc gcc-c++ pcre-deve ...

  3. mvn多模块开发消除重复依赖造成的打包失败

    错误信息: [ERROR] Failed to execute goal on project xiaoyiweifu-core: Could not resolve dependencies for ...

  4. css3的loadding效果

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

  5. [转]从数据库中导出用友U8的现存量数据到Excel表

    转载自:http://www.czerp.com.cn/page/Default.asp?ID=372 可通过Excel获取外部数据的方式与SQL数据库创建查询连接,并导入到Excel中: Selec ...

  6. LeetCode_Letter Combinations of a Phone Number

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  7. MSP430F149模拟IIC读写24C02程序

    板子上设置了EEPROM存储器,型号为AT24C02.板子的硬件连接为:SCL--->P2.4,SDA--->P2.5.直接了当,贴上程序! ======================= ...

  8. Linux下ld搜索问题:ld: cannot find -l"XX"

    ld命令行工具(链接库的一个工具)的搜索路径是-L指定的,库名是-l指定的. 比如: ld -L[dir] -l[mylib] --verbose 以上我用可视化的方法显示ld的搜索路径,其结果是居然 ...

  9. Shell变量替换,命令替换,转义字符

    如果表达式中包含特殊字符,Shell 将会进行替换.例如,在双引号中使用变量就是一种替换,转义字符也是一种替换. 举个例子: #!/bin/bash a=10 echo -e "Value ...

  10. case then 的用法 貌似case then不支持别名

    set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgo ALTER PROC [dbo].[usp_SRV_GetALLRelativeProject]@Service ...