http://acm.hdu.edu.cn/showproblem.php?pid=1326

水,不过PE两次,囧

View Code
#include <stdio.h>
#include <stdlib.h>
int cmp(const void*a,const void*b)
{
    return *(int*)b-*(int*)a;
}
int main()
{
    int n,i,s,av,bz;
    int h[60];
    int nCase=1;
    while(scanf("%d",&n),n)
    {
        s=bz=0;
        for(i=0;i<n;i++)
        {
            scanf("%d",h+i);
            s+=h[i];
        }
        qsort(h,n,4,cmp);
        av=s/n;
        for(i=0;i<n;i++)
        {
            if(h[i]-av>0)bz+=h[i]-av;
            if(h[i]-av<=0)break;
        }
        printf("Set #%d\n",nCase++);
        printf("The minimum number of moves is %d.\n\n",bz);
    }
    return 0; 
}