直接模拟过去就OK了
AC代码:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int a[105]; int N; int judge() { for(int i = 1; i < N; i++) if(a[i] != a[0]) return 0; return 1; } int main() { while(scanf("%d", &N) != EOF) { for(int i = 0; i < N; i++) scanf("%d", &a[i]); int ans = 0; while(!judge()) { int tmp = a[N-1] / 2; for(int i = N-1; i > 0; i--) { a[i] = a[i] / 2 + a[i-1] / 2; if(a[i]&1) ans++, a[i]++; } a[0] = a[0] / 2 + tmp; if(a[0]&1) ans++, a[0]++; } printf("%d\n", ans); } return 0; }
原文地址:http://blog.csdn.net/u014355480/article/details/44185753