解题思路:
注意事项: 数组开大一点哦
参考代码:
#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 人评分
不需要数组和指针的做法!!!浏览:1125 |
C语言程序设计教程(第三版)课后习题5.8 (C++代码)浏览:657 |
校门外的树 (C++代码)浏览:867 |
C二级辅导-求偶数和 (C语言代码)浏览:631 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:583 |
C语言程序设计教程(第三版)课后习题7.2 (Java代码)浏览:681 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:967 |
C语言训练-最大数问题 (C语言代码)浏览:633 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:594 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:567 |