Lottery - CodeForces 589I(水)

题目大意:有N个球K个人,现在要给这N个球涂上K种颜色,要求使抽到球的不同颜色的概率一致(N确保是K的倍数),求出来至少要给多少个球重新涂上颜色。

分析:先求出来所有球的每种颜色的个数,然后不到平均数的加上距离平均数的个数即可。

代码如下:

--------------------------------------------------------------------------------------------------------------------------------------

#include<stdio.h>
#include<string.h>

const int MAXN = 107;

int color[MAXN];

int main()
{
    int N, K, ci;

    while(scanf("%d%d", &N, &K) != EOF)
    {
        memset(color, 0, sizeof(color));

        for(int i=0; i<N; i++)
        {
            scanf("%d", &ci);
            color[ci] += 1;
        }

        int ave = N/K, ans=0;

        for(int i=1; i<=K; i++)
        {
            if(color[i] < ave)
                ans += ave - color[i];
        }

        printf("%d\n", ans);
    }

    return 0;
}

 

posted @ 2015-10-26 19:19  无忧望月  阅读(146)  评论(0编辑  收藏  举报
levels of contents