题目
AC代码
这道题难倒是不难,但是比较麻烦,debug搞了很久不过最终还是过了。
#include <iostream>
#include <cstring>
using namespace std;
//一轮开始的个数
int numbers[110];
//一轮结束的个数
int numbers2[110];
int main(){
int n;
int playSum = 0;
int average;
int i;
bool flag = true;;
while(1){
scanf("%d",&n);
if(n==0){
break;
}
for(i=0;i<n;i++){
scanf("%d",&numbers[i]);
}
for(i=0;i<n;i++){
if(i>=1&&numbers[i]!=numbers[i-1]){
flag = false;
}
}
if(flag){
average = numbers[0];
printf("%d %d\n",playSum,average);
}else{
while(1){
for(i=1;i<n;i++){
numbers2[i] = (numbers[i-1]/2) + (numbers[i]/2);
if(numbers2[i]%2!=0){
numbers2[i]++;
}
}
numbers2[0] = (numbers[0]/2) + (numbers[n-1]/2);
if(numbers2[0]%2!=0){
numbers2[0]++;
}
flag = true;
for(i=0;i<n;i++){
numbers[i] = numbers2[i];
if(i>=1&&numbers[i]!=numbers[i-1]){
flag = false;
}
}
playSum++;
if(flag){
average = numbers[0];
printf("%d %d\n",playSum,average);
break;
}
}
}
playSum=0;
}
return 0;
}