解题思路:
注意事项:
参考代码:
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语言训练-斐波纳契数列 (C语言代码)浏览:2811 |
C语言考试练习题_排列 (C语言代码)浏览:1315 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:577 |
淘淘的名单 (C语言代码)浏览:1090 |
WU-复数求和 (C++代码)浏览:1995 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:575 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:371 |
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:819 |
1024题解浏览:806 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:1147 |