zoukankan      html  css  js  c++  java
  • 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest I Lottery

    LotteryCrawling in process... Crawling failed Time Limit:2000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u

    Submit Status

    Description

     

    Input

     

    Output

     

    Sample Input

     

    Sample Output

     

    Hint

     

    Description

    Today Berland holds a lottery with a prize — a huge sum of money! There are k persons, who attend the lottery. Each of them will receive a unique integer from 1 to k.

    The organizers bought n balls to organize the lottery, each of them is painted some color, the colors are numbered from 1 to k. A ball of color c corresponds to the participant with the same number. The organizers will randomly choose one ball — and the winner will be the person whose color will be chosen!

    Five hours before the start of the lottery the organizers realized that for the lottery to be fair there must be an equal number of balls of each of k colors. This will ensure that the chances of winning are equal for all the participants.

    You have to find the minimum number of balls that you need to repaint to make the lottery fair. A ball can be repainted to any of the k colors.

    Input

    The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 100) — the number of balls and the number of participants. It is guaranteed that n is evenly divisible by k.

    The second line of the input contains space-separated sequence of n positive integers ci (1 ≤ ci ≤ k), where ci means the original color of the i-th ball.

    Output

    In the single line of the output print a single integer — the minimum number of balls to repaint to make number of balls of each color equal.

    Sample Input

     
    Input
    4 2
    2 1 2 2
    Output
    1
    Input
    8 4
    1 2 1 1 1 4 1 4
    Output
    3

    Sample Output

     

    Hint

    In the first example the organizers need to repaint any ball of color 2 to the color 1.

    In the second example the organizers need to repaint one ball of color 1 to the color 2 and two balls of the color 1 to the color 3.

    /*
    大水题,最后才看到真是可惜啊
    k个人n个球,n是k的倍数
    每个人都有初始的球数,让你球使每个人的球数都相等的,最少要改变多少球数
    */
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #define N 105
    using namespace std;
    int n,k,x;  
    int a[N];  
    int main()  
    {  
        while(~scanf("%d%d",&n,&k))  
        {  
            memset(a,0,sizeof a);
            int ave=n/k;  
            for(int i=1;i<=n;i++)  
            {  
                scanf("%d",&x);  
                ++a[x];  
            }  
            int ans=0;  
            for(int i=1;i<=k;i++)ans+=abs(a[i]-ave);  
            printf("%d
    ",ans>>1);  
        }  
        return 0;  
    }  
  • 相关阅读:
    【学相伴】Nginx最新教程通俗易懂-狂神说
    Linux基础知识总结(命令行)
    CentOS7 运维
    Linux 的基础知识回顾(安装vmware) ---- No.1 后面都以Centos8 为例
    Linux sudo权限提升漏洞(CVE-2021-3156)
    Flutter开发指南之理论篇:Dart语法05(单线程模型,事件循环模型,Isolate)
    矩阵的范数
    函数导出在kvm_intel.ko,kvm.ko不共享
    python 调用内部类的两种方法
    python3 字符串方法
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/5791122.html
Copyright © 2011-2022 走看看