hduoj 1034「建议收藏」

hduoj 1034「建议收藏」CandySharingGameTimeLimit:2000/1000MS(Java/Others)    MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):5890    AcceptedSubmission(s):3580ProblemDescriptionAnumberof

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全家桶1年46,售后保障稳定

Candy Sharing Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5890    Accepted Submission(s): 3580

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

Jetbrains全家桶1年46,售后保障稳定

 

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.
比较坑的地方是一个人必须先给下一个才能拿上一个人的,之前一直理解错误
代码:
#include<algorithm> #include<iostream> #include<cstring> #include<cmath> using namespace std; int cake[10010]; int n; int pan() {  int t = cake[0];  for(int i = 1;i < n;i++)   {    if(t != cake[i])    {     return 1;    }   }   return 0; } int main() {    while(cin >> n&&n)  {   for(int i = 0;i < n;i++) cin >> cake[i];   int ans = 0;   while(pan())   {    ans++;    int tem = cake[n-1]/2;    for(int i = n-1;i > 0;i--)    {     cake[i] = cake[i]/2+cake[i-1]/2;     if(cake[i] % 2) cake[i]++;    }    cake[0] = cake[0]/2 + tem;    if(cake[0] % 2) cake[0]++;   }   cout << ans << " " << cake[0] << endl;  }  return 0;
}
比比较
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/234351.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • 微信小程序实现banner图轮播(动态获取数据),自动获取图片高度

    微信小程序实现banner图轮播(动态获取数据),自动获取图片高度效果图:indicator-active-color=”#007aff”//当前选中的指示点颜色js:constapp=getApp()Page({data:{//———–模拟banner图———–imgUrls:[‘/image/1545118381903.jpg’,’/imag…

  • 盛希泰:中国正经历第4次经济大重启 90后是大变量

    盛希泰:中国正经历第4次经济大重启 90后是大变量

  • java的api类_javaAPI类

    java的api类_javaAPI类扫描器Scanner可以用来从键盘输入读取数据extLine()获取一行字符串nextInt()获取一个整数nextFloat()获取一个浮点数大数字BigInteger如果我们需要操作一个很大的整数,它无法用long来表达时,就可以用BigIntegeradd()加subtract()减multiply()乘divide()除mod()取余包装类ØJDK提供了对所有数据类…

  • Subversion+RabbitVCS 版本控制「建议收藏」

    Subversion+RabbitVCS 版本控制「建议收藏」Ubuntu10.04学习笔记(4)——Subversion+RabbitVCS版本控制2011年04月19日星期二17:281、安装Subversion软件sudoapt-getinstallapache2%先安装apache,配合阅读svn用,并且平时开发也是要用到的sudoapt-getinstallsubversion%svn…

  • 对Java线程池ThreadPoolExecutor的理解分析

    对Java线程池ThreadPoolExecutor的理解分析主要放在后面做总结(重点查看下:http://www.ideabuffer.cn/,刚发现一个宝藏)参考文献:1.http://www.ideabuffer.cn/2017/04/04/%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3Java%E7%BA%BF%E7%A8%8B%E6%B1%A0%EF%BC%9AThreadPoolExecutor/2.https://tech.meituan.com/2020/04/02/java-pooling-pratice-i

  • linux下进程的管理_LINUX教程

    linux下进程的管理_LINUX教程作者:RodmaChen关注我的csdn博客,更多Linux笔记知识还在更新本人只在csdn写博客Linux进程管理一.什么是进程和程序二.查看进程——ps,top,pstree三.进程的启动方式四.进程的控制五.实训任务一.什么是进程和程序进程:开始执行但是还没有结束的程序的实例程序:包含可执行代码的文件进程与程序的关系进程由程序产生,是一个运行着的、要占系统资源的程序进程不等于程序进程与程序是多对一进程是占用(消耗)系统资源的二.查看进程—.

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号