解题思路:
注意事项:分糖和累加右边人所分过来糖的数量是同时进行的QWQ
参考代码:
#include <stdio.h>
int main(){
int a[100]; //每个人所拥有的糖果数量
int n; //人数
int count; //总共补发的糖果数量
int i,t;
count = 0;
scanf("%d", &n);
for(i = 1; i <= n; i++)
scanf("%d", &a[i]);
while(1){
for(i = 1; i <= n; i++){
if(i == 1)
t = a[i]/2;
if(i == n)
a[i] = a[i]/2+t;
else
a[i] = a[i]/2+a[i+1]/2;
}
for(i = 1; i <= n; i++){
if(a[i]%2 == 1){
a[i] += 1;
count++;
}
}
for(i = 2; i <= n; i++){
if(a[1] != a[i])
break;
}
if(i > n)
break;
}
printf("%d", count);
return 0;
}
0.0分
0 人评分