解题思路:
注意事项:
参考代码:
import java.util.Scanner;
public class Main1431 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n= sc.nextInt();
int array[]=new int[n];
int num[]=new int[n];
for (int i = 0; i < n; i++) {
array[i]= sc.nextInt();
}
int count=0;
boolean t=true;
while (t){
int cc=0;
for (cc = 1; cc < n; ) {//判断每个小朋友所得糖果是否相同
if (array[cc]==array[0]){
cc++;
}else
break;
}
if (cc==n){//如果相同则输出
System.out.println(count);
return;
}
for (int i = 0; i < n; i++) {//求出下一次要分出的糖果数量,与分出后每个小朋友手中还剩余的糖果数量
num[i]=array[i]/2;
array[i]=array[i]/2;
}
for (int i = 0; i < n; i++) {//将糖果分出又获得其他小朋友的糖果后,每人手中还剩余的糖果
if (i==0){
array[i]+=num[n-1];
continue;
}
array[i]+=num[i-1];
}
for (int i = 0; i < n; i++) {//判断手中的糖果是否为奇数,是则加1
if (array[i]%2!=0){
array[i]+=1;
count++;
}
}
}
}
}
0.0分
0 人评分
简单的a+b (C语言代码)浏览:573 |
1128题解(返回值为数组的情况)浏览:474 |
C二级辅导-进制转换 (C语言代码)浏览:661 |
简单的a+b (C语言代码)浏览:541 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:721 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:2166 |
1005答案错误为什么浏览:1975 |
众数问题 (C语言代码)浏览:630 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:514 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:531 |