解题思路:
注意事项:
参考代码:
import java.util.Scanner; public class C1431 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); int[] a = new int[n]; for(int i = 0; i < n; i++){ a[i] = sc.nextInt(); } System.out.println(F(a)); } sc.close(); } private static int F(int[] a){ int count = 0; int n = a.length; while(true){ boolean isEqual = true; int temp = a[0]/2 + a[n-1]/2; //最后一个数 if(temp % 2 == 1){ temp += 1; count++; } for(int i = 0; i < n-1; i++){ a[i] = a[i]/2 + a[i+1]/2; if(a[i] % 2 == 1){ a[i] += 1; count++; } if(isEqual){ if(temp != a[i]){ isEqual = false; } } } a[n-1] = temp; if(isEqual) break; } return count; } }
0.0分
4 人评分
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:643 |
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:647 |
数组输出 (C语言代码)--此题的题目描述有问题浏览:1817 |
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:1229 |
蛇行矩阵 (C语言代码)浏览:536 |
罗列完美数 (C语言代码)浏览:491 |
2005年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:577 |
C语言程序设计教程(第三版)课后习题12.5 (C语言代码)浏览:766 |
拆分位数 (C语言代码)浏览:522 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:817 |