zoukankan      html  css  js  c++  java
  • CodeForce 677I Lottery

     Lottery
     

    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.

    Examples
    Input
     
    4 2
    2 1 2 2
    Output
     
    1
    Input
     
    8 4
    1 2 1 1 1 4 1 4
    Output
     
    3
    Note

    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.

    思路:

      简单水题

    AC代码:

     1 # include <iostream>
     2 # include <cstring>
     3 using namespace std;
     4 int vis[101];
     5 int main()
     6 {
     7     int n, k;
     8     memset(vis, 0, sizeof(vis));
     9     cin >> n >> k;
    10     for(int i = 1; i <= n; i++)
    11     {
    12         int t;
    13         cin >> t;
    14         vis[t]++;
    15     }
    16     int haha = n / k;
    17     int sum = 0;
    18     for(int i = 1; i <= k; i++)
    19     {
    20         if(vis[i] > haha)
    21             sum += vis[i] - haha;
    22     }
    23     cout << sum << endl;
    24     return 0;
    25 }
    View Code
    生命不息,奋斗不止,这才叫青春,青春就是拥有热情相信未来。
  • 相关阅读:
    ES6(严格模式,let&const,箭头函数,解构赋值,字符串扩展方法,Symbol,Set和Map,生成器函数)
    动画实现-微信语音小喇叭样式
    JS与React分别实现倒计时(天时分秒)
    MacOS下如何设置hosts?
    原生JS实现‘点击元素切换背景及字体等’
    mysql数据库设计规范
    如何对 ElasticSearch 集群进行压力测试
    设计实现SAM--无服务器应用模型
    韩立刚计算机网络笔记-第11章 因特网上的音频视频-无线网络
    韩立刚计算机网络笔记-第10章 网络安全
  • 原文地址:https://www.cnblogs.com/lyf-acm/p/5791516.html
Copyright © 2011-2022 走看看