HDU1034 Candy Sharing Game
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.
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
#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的更多相关文章
- HDU-1034 Candy Sharing Game 模拟问题(水题)
题目链接:https://cn.vjudge.net/problem/HDU-1034 水题 代码 #include <cstdio> #include <algorithm> ...
- POJ - 1666 Candy Sharing Game
这道题只要英语单词都认得,阅读没有问题,就做得出来. POJ - 1666 Candy Sharing Game Time Limit: 1000MS Memory Limit: 10000KB 64 ...
- hdu 1034 Candy Sharing Game
Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- Candy Sharing Game(模拟搜索)
Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- M - Candy Sharing Game
Description A number of students sit in a circle facing their teacher in the center. Each student in ...
- Candy Sharing Game(hdoj1034)
Problem Description A number of students sit in a circle facing their teacher in the center. Each st ...
- HDU 1034 Candy Sharing Game (模拟)
题目链接 Problem Description A number of students sit in a circle facing their teacher in the center. Ea ...
- sicily 1052. Candy Sharing Game
Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description A number of students sit in a circle ...
- 九度OJ 1145:Candy Sharing Game(分享蜡烛游戏) (模拟)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:248 解决:194 题目描述: A number of students sit in a circle facing their teac ...
随机推荐
- 就是要你懂Java中volatile关键字实现原理
原文地址http://www.cnblogs.com/xrq730/p/7048693.html,转载请注明出处,谢谢 前言 我们知道volatile关键字的作用是保证变量在多线程之间的可见性,它是j ...
- CC2530入门教程-02】CC2530的通用I/O端口输入和输出控制
第2课 CC2530的通用I/O端口输入和输出控制 广东职业技术学院 欧浩源 一.CC2530的引脚概述 CC2530微控制器采用QFN40封装,有40 个引脚.其中,有21个数字I/O端口,其中 ...
- 流畅的python学习笔记:第五章
在python中一切都可以视作为对象,包括函数.我们来看个例子: def function_try(): '''it is funciton try doc''' print 'fun ...
- 简单轻量级的一套JS 类库(RapidDevelopmentFramework.JS)
1.最近好久没有更新自己的博客了,一直在考虑自己应该写一些什么.4.2日从苏州回到南京的路上感觉自己的内心些崩溃和失落,我就不多说了? 猛然之间我认为自己需要找一下内心的平衡.决定开发属于自己一套快速 ...
- Java 变量类型
局部变量 成员变量 类变量 Java局部变量 局部变量声明在方法.构造方法或者语句块中: 局部变量在方法.构造方法.或者语句块被执行的时候创建,当它们执行完成后,变量将会被销毁: 访问修饰符不能用于局 ...
- el表达式字符串使用总结
el表达式截取 逗号后面的字符串${fn:substringAfter(strVar,',' )} el表达式判断字段长度<c:if test="${fn:length(strVar) ...
- 《JavaScript高级程序设计》笔记一
第一章 JavaScript简介 一.JavaScript的起源 JavaScript诞生于1995年.当时,它的主要作用是处理一些输入验证操作.之前的话,都是把表单数据发送到服务器端,然后再去判断有 ...
- ES语法注意事项
在函数内部定义全局变量:举个栗子 function fn(){ var str = "hezhi"; } -alert(str) //=>fn不执行的 =>str is ...
- 数据结构(C语言版)顺序栈相关算法的代码实现
这两天完成了栈的顺序存储结构的相关算法,包括初始化.压栈.出栈.取栈顶元素.判断栈是否为空.返回栈长度.栈的遍历.清栈.销毁栈.这次的实现过程有两点收获,总结如下: 一.清楚遍历栈的概念 栈的遍历指的 ...
- Symbol() 的使用方法
简介:ES5的对象属性名都是字符串,这就很容易造成属性名的冲突,比如一个项目很庞大,又不是一个人开发 的,就有可能会造成变量名冲突,如果有一个独一无二的名字就好了,这样就能从根本上防止属性名冲突.这就 ...