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
15 14 17 22 4 8HintThe 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>
using namespace std;
int main()
{
int ls[100],count,i,N,t;
while(cin>>N,N)
{
count=0;
for(i=1;i<=N;i++)
cin>>ls[i];
for(int k=0;;count++,k++)
{
int y=ls[N]=ls[N]/2;
for(int j=N;j>1;j--)
{ ls[j-1]/=2;
ls[j]+=ls[j-1];
}
ls[1]+=y;
for(int m=1;m<=N;m++)
if(ls[m]%2==1)
ls[m]+=1;
for( t=2;t<=N;t++)
{
if(ls[t]!=ls[t-1])
{
break;
}
}
if(t>N)
{cout<<count+1<<" "<<ls[t-1]<<endl;break;}
else
continue;
}
}
return 0;
}
杭电 HDU 1034 Candy Sharing Game
原文:http://blog.csdn.net/lsgqjh/article/details/44604017