【02NOIP提高组】均分纸牌
#include<bits/stdc++.h> using namespace std; const int maxn=105; int n,sum,a[maxn]; int main() { int i,j,step=0; cin>>n; for(i=1;i<=n;i++)scanf("%d",&a[i]),sum+=a[i]; sum/=n; for(i=1;i<=n;i++) a[i]-=sum; i=1; while(i<n&&a[i]==0) i++; j=n; while(j>1&&a[j]==0) j--; while(i<j) {a[i+1]+=a[i]; a[i]=0; step++; i++; while(a[i]==0&&i<j) i++; } printf("%d",step); return 0; }