Candy Sharing Game(hdoj1034)
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.
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.
followed by the amount of candy each child ends up with, both on one
line.
目说的是一个分糖果的游戏,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)的更多相关文章
- 九度OJ 1145:Candy Sharing Game(分享蜡烛游戏) (模拟)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:248 解决:194 题目描述: A number of students sit in a circle facing their teac ...
- 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 ...
- OpenStack 企业私有云的若干需求(3):多租户和租户间隔离(multi-tenancy and isolation)
本系列会介绍OpenStack 企业私有云的几个需求: 自动扩展(Auto-scaling)支持 多租户和租户隔离 (multi-tenancy and tenancy isolation) 混合云( ...
- (译)iOS Code Signing: 解惑
子龙山人 Learning,Sharing,Improving! (译)iOS Code Signing: 解惑 免责申明(必读!):本博客提供的所有教程的翻译原稿均来自于互联网,仅供学习交流之用,切 ...
- 第8章 传输层(1)_TCP/UDP协议的应用场景
1. 传输层的两个协议 1.1 TCP和UDP协议的应用场景 (1)TCP协议:如果要传输的内容比较多,需要将发送的内容分成多个数据包发送.这就要求在传输层用TCP协议,在发送方和接收方建立连接,实现 ...
- 《NVM-Express-1_4-2019.06.10-Ratified》学习笔记(1)
材料说明: 文档<NVM-Express-1_4-2019.06.10-Ratified.pdf>来自于NVMe网站:https://nvmexpress.org/ 笔记目的是学习NVMe ...
- 【树状数组(二叉索引树)】轻院热身—candy、NYOJ-116士兵杀敌(二)
[概念] 转载连接:树状数组 讲的挺好. 这两题非常的相似,查询区间的累加和.更新结点.Add(x,d) 与 Query(L,R) 的操作 [题目链接:candy] 唉,也是现在才发现这题用了这个知识 ...
- Ajax:Cross-Origin Resource Sharing(转)
实例:http://blog.csdn.net/hongweigg/article/details/39054403 通过XHR实现Ajax通信的一个主要限制,来源于跨域安全策略.默认情况下,XHR对 ...
- Cross-Origin Resource Sharing(CORS)详解,CORS详解,CORS原理分析
Keywords CORS, 跨域,JS跨域调用,Ajax CORS 跨域,跨域详解,CORS跨域原理 Cross-Origin Resource Sharing详解 Cross-Origin Res ...
随机推荐
- python笔记之提取网页中的超链接
python笔记之提取网页中的超链接 对于提取网页中的超链接,先把网页内容读取出来,然后用beautifulsoup来解析是比较方便的.但是我发现一个问题,如果直接提取a标签的href,就会包含jav ...
- 梯田(dfs)
梯田 Time Limit: 2000 ms Memory Limit: 256 MBTotal Submission: 26 Submission Accepted: 5 Descrip ...
- 转:使用C#的HttpWebRequest模拟登陆网站
这篇文章是有关模拟登录网站方面的. 实现步骤: 启用一个web会话 发送模拟数据请求(POST或者GET) 获取会话的CooKie 并根据该CooKie继续访问登录后的页面,获取后续访问的页面数据. ...
- LeeCode-Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...
- redhat6.3 64位更新源(使用网易源)全过程记录
本篇博客参考:http://chinaxiaoyu.diandian.com/post/2013-01-24/40046529897.首先在浏览器中输入http://tel.mirrors.163.c ...
- wget命令3(转载)
Wget下载终极用法和15个详细的例子 Wget是一种很好用的因特网下载工具,他具有的很多特性是其他工具所不能比拟的,再者他是一个轻量级可配置的下载工具. 本文结合例子介绍Windows下wget的多 ...
- 【转】android 电容屏(三):驱动调试之驱动程序分析篇
关键词:android 电容屏 tp 工作队列 中断 坐点计算 电容屏主要参数平台信息:内核:linux2.6/linux3.0系统:android/android4.0 平台:S5PV310( ...
- 【转】Android LCD(三):Samsung LCD接口篇
关键词:android LCD控制器 Framebuffer PWM 平台信息:内核:linux2.6/linux3.0系统:android/android4.0 平台:samsung exynos ...
- MSSQL 镜像
1.设置数据库CollectionDB 为完整备份模式服务端: USE master ALTER DATABASE CollectionGuest SET RECOVERY FULL GO 镜相端: ...
- hdu 3954 Level up(线段树)
题目链接:hdu 3954 Level up 题目大意:N个英雄,M个等级,初始等级为1,给定每一个等级须要的经验值,Q次操作,操作分两种,W l r x:表示l~r之间的英雄每一个人杀了x个怪物:Q ...