#include<bits/stdc++.h> using namespace std; const int maxn=1e4; int pre[maxn],n,ans=0; int a[maxn]; int check(){ for(int i=2;i<=n;i++){ if(a[i]!=a[i-1])return 0; } return 1; } int main() { cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; while(!check()){ for(int i=1;i<=n;i++){ if(check()){ cout<<ans<<endl; return 0; } if(i==n){ pre[1]=a[i]/2; a[i]/=2; } else{ pre[i+1]=a[i]/2; a[i]/=2; } } for(int i=1;i<=n;i++){ a[i]+=pre[i]; if(a[i]&1){ ans++; a[i]++; } } } cout<<ans<<endl; return 0; }
原文:https://www.cnblogs.com/mohari/p/12927517.html