zoukankan      html  css  js  c++  java
  • codeforces 589 I

    I - Lottery
    Time Limit:2000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u

    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 kcolors.

    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

    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.

     1 /*************************************************************************
     2     > File Name: code/hust/20151025/I.cpp
     3     > Author: 111qqz
     4     > Email: rkz2013@126.com 
     5     > Created Time: 2015年10月25日 星期日 13时09分42秒
     6  ************************************************************************/
     7 
     8 #include<iostream>
     9 #include<iomanip>
    10 #include<cstdio>
    11 #include<algorithm>
    12 #include<cmath>
    13 #include<cstring>
    14 #include<string>
    15 #include<map>
    16 #include<set>
    17 #include<queue>
    18 #include<vector>
    19 #include<stack>
    20 #include<cctype>
    21                  
    22 #define yn hez111qqz
    23 #define j1 cute111qqz
    24 #define ms(a,x) memset(a,x,sizeof(a))
    25 using namespace std;
    26 const int dx4[4]={1,0,0,-1};
    27 const int dy4[4]={0,-1,1,0};
    28 typedef long long LL;
    29 typedef double DB;
    30 const int inf = 0x3f3f3f3f;
    31 int n,k;
    32 int cnt[111];
    33 
    34 bool cmp( int a,int b)
    35 {
    36     return a>b;
    37 }
    38 int main()
    39 {
    40   #ifndef  ONLINE_JUDGE 
    41    freopen("in.txt","r",stdin);
    42   #endif
    43 
    44    scanf("%d %d",&n,&k);
    45    ms(cnt,0);
    46    for ( int i = 0 ; i < n ; i++)
    47     {
    48     int x;
    49     scanf("%d",&x);
    50     cnt[x]++;
    51     }
    52     sort(cnt,cnt+105,cmp);
    53     int ans = 0 ;
    54     int ave = n/k;
    55     for ( int i  = 0 ;  i < 105 ; i++)
    56     {
    57     if (cnt[i]<=ave) break;
    58     else ans+=cnt[i]-ave;
    59     }
    60     printf("%d
    ",ans);
    61   
    62    
    63  #ifndef ONLINE_JUDGE  
    64   fclose(stdin);
    65   #endif
    66     return 0;
    67 }
    View Code
  • 相关阅读:
    HDOJ 2076 夹角有多大(题目已修改,注意读题)
    HDOJ 2058 The sum problem
    HDOJ 2099 整除的尾数
    HDOJ 2075 A|B?
    HDOJ 2071 Max Num
    HDOJ 2056 Rectangles
    HDOJ 2055 An easy problem
    HDOJ 2053 Switch Game
    HDOJ 2052 Picture
    P4139 上帝与集合的正确用法
  • 原文地址:https://www.cnblogs.com/111qqz/p/4912751.html
Copyright © 2011-2022 走看看