解题思路:
注意事项: 数组开大一点哦
参考代码:
#include <stdio.h> #include <iostream> #include <algorithm> using namespace std; const int maxn = 1000010; int n,cnt; int a[maxn]; bool judge(){ bool flag = true; for(int i = 0; i < n - 1; i++){ if(a[i] == a[i+1]) flag = true; else { flag = false; break; } } return flag; } int main(void){ // freopen("input4.txt","r",stdin); int max = 0; cin >> n; for(int i = 0; i < n; i++){ cin >> a[i]; } while(!judge()){ int tmp = a[0]; for(int i = 0; i < n; i++){ if(i == n-1) a[n-1] = a[n-1]/2 + tmp/2; else a[i] = a[i]/2 + a[i+1]/2; if(a[i]%2 != 0){ a[i] += 1; cnt++; } } } cout << cnt; // fclose(stdin); return 0; }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:698 |
C二级辅导-求偶数和 (C语言代码)浏览:640 |
printf基础练习2 (C语言代码)浏览:305 |
C语言训练-数字母 (C语言代码)浏览:650 |
WU-输出九九乘法表 (C++代码)浏览:1683 |
简单的a+b (C语言代码)浏览:614 |
WU-C语言程序设计教程(第三版)课后习题12.1 (C++代码)浏览:943 |
a+b浏览:433 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:531 |
有关字符,字符串的输入输出函数说明浏览:480 |