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;
}
比比较
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 绘制自己的人际关系图简单_网络给人际关系带来的影响

    绘制自己的人际关系图简单_网络给人际关系带来的影响如何系统的绘制自己的人际关系网络图?人际关系网络的分类对于人际关系网络,国内外研究比较多的是社交网络,社交网络分双向和单项,比如脸书,微信就是双向(add),微博,Twitter就是单向(flower)。我个人把双向网络归纳为强关系网络,在人际关系网中是不容易破裂的,两个人互加为好友,若干年后还是好友!单向网络是弱关系网络,在人际关系网络中是容易断裂的,你某天关注了某位明星,也许从此以后你都没在看…

    2025年7月9日
    0
  • tinyxml 内存泄露_tinyxml 用法[通俗易懂]

    tinyxml 内存泄露_tinyxml 用法[通俗易懂]场景说明:创建一个空的xml文件,要求格式如下:代码如下:TiXmlElement*RootElement=NULL;TiXmlDocument*pDoc=NULL;pDoc=newTiXmlDocument();TiXmlDeclaration*pDeclaration=newTiXmlDeclaration((“1.0”),(“UTF-8”),(“”));pDoc-&…

    2022年6月9日
    53
  • 《欧美剧集观看最佳索引》(US SHOWS GUIDE) 【2005-12-27 转verycd】

    《欧美剧集观看最佳索引》(US SHOWS GUIDE) 【2005-12-27 转verycd】原文地址http://bbs.verycd.com/topics/230847/中文名称:欧美剧集观看最佳索引英文名称:USTVSHOWSGUIDE别名:欧美剧集观看最佳索引版本:2005-2006导演:USTVSHOWSGUIDE演员:USTVSHOWSGUIDE简介:欧美剧集观看最佳索引2005-2006USTVSHOWSGUIDE2005-2006(作者:

    2022年5月6日
    57
  • 13 RangeValidator

    13 RangeValidatorRangeValidator的属性有:MinimumValue:范围的最小值;MaximumValue:范围的最大值。Type:为数据类型,包括String,Intege,Double,Date,CurrencyRangeValidator,CompareValidator,RegularExpressValidator都不会对非空值进行校验,所…

    2022年7月12日
    20
  • groupid和artifactid的区别是啥(中人是指哪些人)

    最近用Maven创建工程,一直搞不懂Maven中的GroupID和ArtifactID是什么,直到看了网上的一篇文章才明白,在此与大家分享分享 本文转载于一问网友的回答(略修改) 地址:https://zhidao.baidu.com/question/1639120287056394340.html    GroupId和ArtifactId被统称为“坐标”是为了保证项目唯一性而提出的…

    2022年4月16日
    54
  • executescalar mysql_ExecuteScalar[通俗易懂]

    executescalar mysql_ExecuteScalar[通俗易懂]这两个答案和一点点思考使我想到了一个接近答案的东西。首先再澄清一下:该应用程序是用C#(2.0+)编写的,并使用ADO.NET与SQLServer2005进行通信。镜像设置是托管主体和镜像的两个W2k3服务器以及托管作为监视器的快速实例的第三个服务器。这样做的好处是,故障转移对于使用数据库的应用程序几乎是透明的,它将对某些连接引发错误,但从根本上讲一切都会很好地进行。是的,我们得到了奇怪的误报…

    2022年6月30日
    25

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

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