codeforces589I
Lottery
Today Berland holds a lottery with a prize — a huge sum of money! There are kpersons, 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
- 4 2
2 1 2 2
- 1
- 8 4
1 2 1 1 1 4 1 4
- 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.
sol:略水,小学奥数随便搞搞,原题地址已经没了,我也不知道自己写的对不对
- #include <bits/stdc++.h>
- using namespace std;
- typedef int ll;
- inline ll read()
- {
- ll s=;
- bool f=;
- char ch=' ';
- while(!isdigit(ch))
- {
- f|=(ch=='-'); ch=getchar();
- }
- while(isdigit(ch))
- {
- s=(s<<)+(s<<)+(ch^); ch=getchar();
- }
- return (f)?(-s):(s);
- }
- #define R(x) x=read()
- inline void write(ll x)
- {
- if(x<)
- {
- putchar('-'); x=-x;
- }
- if(x<)
- {
- putchar(x+''); return;
- }
- write(x/);
- putchar((x%)+'');
- return;
- }
- #define W(x) write(x),putchar(' ')
- #define Wl(x) write(x),putchar('\n')
- const int N=;
- int n,m,Ges[N];
- int main()
- {
- int i,ans=;
- R(n); R(m);
- for(i=;i<=n;i++)
- {
- Ges[read()]++;
- }
- int oo=n/m;
- for(i=;i<=m;i++) ans+=abs(Ges[i]-oo);
- Wl(ans>>);
- return ;
- }
- /*
- Input
- 4 2
- 2 1 2 2
- Output
- 1
- Input
- 8 4
- 1 2 1 1 1 4 1 4
- Output
- 3
- */
codeforces589I的更多相关文章
随机推荐
- MySQL笔记--注意
replace into 和 insert into..... on duplicate key update的异同 同:1. 当key不存在时,两者相同,都是插入一条数据2. key存在时,执行两者 ...
- face recognition[variations of softmax][ArcFace]
本文来自<ArcFace: Additive Angular Margin Loss for Deep Face Recognition>,时间线为2018年1月.是洞见的作品,一作目前在 ...
- RichTextbox下Hyperlink的Click无效
原文:RichTextbox下Hyperlink的Click无效 两种方式解决: 1.<RichTextBox IsReadOnly="True" IsDocumentEna ...
- 从统计局采集最新的省市区镇数据,用js在浏览器中运行 V2
本文描述的是对国家统计局于2019-01-31发布的<2018年统计用区划代码和城乡划分代码(截止2018年10月31日)>的采集. 相对于用于和采集2016版.2017版的js代码做了比 ...
- 我们都被GitHub出卖了!逃跑吧兄弟!
周一突然间爆出微软以75亿收购GitHub可真是一颗重磅炸弹,一下轰动整个软件业.如果你不是搞开发的这篇文章几本不会引起你的共鸣:如果你没有用源代码管理这个消息也只不过是个新闻:如果你是微软系的朋友那 ...
- Ubuntu 18.04 根目录为啥只有 4G 大小
其实准确点儿的描述应该是:Ubuntu Server 18.04 ,设置 LVM,安装完成后根目录的容量为什么只有 4G?只有 Server 版有问题,Desktop 版没有问题,Ubuntu 16. ...
- elasticsearch简单操作(二)
让我们建立一个员工目录,假设我们刚好在Megacorp工作,这时人力资源部门出于某种目的需要让我们创建一个员工目录,这个目录用于促进人文关怀和用于实时协同工作,所以它有以下不同的需求:1.数据能够包含 ...
- OO博客作业4:第13-14周作业总结
一.论述测试与正确性论证的效果差异,比较其优缺点 测试是设计若干组测试用例,运行程序并检验其是否完成预期功能.测试是一种直接发现BUG的方法,可以准确断定什么样的BUG会发生,并通过辅助调试进一步确定 ...
- centos7下zabbix安装与部署
1.Zabbix介绍 zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系 ...
- c++入门之运算符重载
c++函数重载:可以将一个函数名用于不同功能的函数.从而处理不同的对象.对于运算符,同样也有这样的用途,即对同一个标志符的运算符,可以运用到不同的功能中去. 首先引入:运算符重载,在C语言中甚至都有运 ...