【 OJ 】 HDOJ1034 18年11月17日12:38 [ 31 ]
阿新 • • 發佈:2018-11-17
ummm 之前1033完全看不懂題目意思......
本題模擬AC
# include<iostream> using namespace std; int a[1000]; bool isok(int N) { int n = a[0]; for (int i = 1; i < N; i++){ if (a[i] != n) return false; } return true; } int main(void) { int N;// N個學生 int tl, tr; int c; cin >> N; while (N) { c = 0;//計數多少次 for (int i = 0; i < N; ++i) { cin >> a[i]; }//錄入資料 while (1) { c++; tr = tl = 0; for (int i = 0; i < N; ++i) { tr = (a[i] /=2); a[i] += tl; tl = tr; if (i&&a[i] & 1) a[i] += 1; }//拆一半 a[0] += tl; if (a[0] & 1) a[0] += 1; if (isok(N)) break; }//操作完成 cout <<c<<" "<<a[0]<<endl; cin >> N; } system("pause"); return 0; }