P1031均分纸牌
#include<bits/stdc++.h>
using namespace std;
int n,a[105],ave,step;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
ave+=a[i];
}
ave/=n;
for(int i=1;i<=n;i++){
a[i]-=ave;
}
int i=1,j=n;
while(i<j&&a[i]==0) i++;
while(i<j&&a[j]==0) j--;
while(i<j){
a[i+1]+=a[i];
step++;
i++;
while(i<j&&a[i+1]==0) i++;
}
cout<<step;
return 0;
}