【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;
}

 

posted @ 2019-10-24 20:36  Gold_stein  阅读(189)  评论(0编辑  收藏  举报