/*1052. Candy Sharing Game
大意:同学坐成一圈,逆时针给自己手中一半糖果(同时!!!)
一轮结束后,奇数个糖果的同学,老师给1个补充。
求需要多少轮后,所有同学手中糖果数一样多,并且输出每人的糖果数
*/
#include<iostream>
#include<stdlib.h>
using namespace std;
int N;
int candy[10000];
int half[10000];
int num;
int getRoundNum(){
bool ok = true;
while(1){
num++;
int start, passNum, tempStart, end;
for(int i =0; i<N; i++){
half[i] = candy[i]/2;
candy[i] /= 2;
}
for(int i = 0; i<N; i++){
candy[(i+1)%N] += half[i];
}
for(int i =0; i<N; i++){
if(candy[i] % 2 == 1)
candy[i]++;
}
ok = true;
for(int i =1; i<N; i++){
if(candy[i] != candy[0]){
ok = false;
}
}
if(ok) {
return num;
}
}
return num;
}
int main()
{
while(cin >> N && N!=0){
num = 0;
for(int i = 0; i<N; i++)
cin >> candy[i];
int n = getRoundNum();
//这里注意,不能写成 cout << getRoundNum() << " " << candy[0] << endl;
//不知道为啥,可能是因为cout时先把后面的入栈,那么candy[0]在调用getRoundNum之前,出错了。。
cout << n << " " << candy[0] << endl;
}
system("pause");
return 0;
}
Sicily.1052. Candy Sharing Game
最新推荐文章于 2015-11-01 09:35:27 发布