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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 博客园博客背景图片设置

    博客园博客背景图片设置首先在博客园后台管理页面的相册上传自己想要设置背景的图片:上传完成之后点击该图片进去:看到大图再通过控制台获取路径然后转到设置:加上如下代码:最后效果:

    2022年7月4日
    22
  • Pycharm中Debug的基本用法和高级技巧

    Pycharm中Debug的基本用法和高级技巧今天测试自己写的代码,测试了很多次都是实际结果与心里预测不相符,甚至一度怀疑Pycharm除了问题,哈哈。最后debug了一下,才发现是自己的操作问题才导致了错误的结果,看来Debug真的是个好侦探,让你不会乱怀疑。下面就和大家分享一下我在Pycharm上Debug的心得1.在Pycharm中打开一个.py文件,并设置断点鼠标左键单击箭头处需要设置断点的语句即可设置断点2.运行debug…

    2022年8月26日
    6
  • idea配置Tomcat_tomcat docbase

    idea配置Tomcat_tomcat docbaseidea配置tomcaterror:duplicatecontextpath 解决方法:    在editconfig中部署tomcat,     server         tomcathome            D:\software……\apache-tomcat-7.0.65   …

    2025年12月14日
    7
  • 基于jQuery 常用WEB控件收集

    基于jQuery 常用WEB控件收集

    2021年8月30日
    60
  • 朋友圈一键集赞_朋友圈秒赞怎么做到的

    朋友圈一键集赞_朋友圈秒赞怎么做到的哈喽,今天又来给大家伙推荐神器啦~相信各位都曾遇到或亲身参与过朋友圈集赞活动。比如说部分商家、公众号为了达到宣传和涨粉的需求,要求用户转发相关的活动文章、海报到朋友圈,集满一定数量的赞后,才会给予相应的优惠或福利。这种动辄几十,上百的集赞要求,对于平时连朋友圈都懒得发的社畜来说,难度系数直逼五颗星。其一是碍于面子不便集赞,二是实在没有那么多朋友来给自己点赞。图片可是,商家、公众号们赠送的活动福利实在是“太香了”!虽然没有威逼,但是在利诱之下,难免不心动。正所谓,有需求就有市场。用户存在集赞难的痛点,

    2025年9月20日
    7
  • c语言二维数组传参数_c语言数组传参

    c语言二维数组传参数_c语言数组传参初遇二维数组作函数参数,宛如自己化身为了大头儿子。很头大。不禁大声呐喊:该怎么声明定义,该怎么调用,又该怎么函数中操作元素和地址?在此,我要拨开这些问题的一些迷雾。我相信,有心人看完后,再遇就不会怕了。其实声明,定义是一样的。因此,只写声明。同时,把元素外层*()剥去就代表地址。因此只写元素。最后有总结。二维数组作函数参数,依我看来,至少可以分成三种。事先,在main函数中int…

    2025年6月18日
    4

发表回复

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

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