Lottery (水题)
来源:互联网 发布:中国gdp数据折线图 编辑:程序博客网 时间:2024/06/05 00:43
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
4 22 1 2 2
1
8 41 2 1 1 1 4 1 4
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.
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int a[110];int main(){int n,m,mm,i,j,k;while(scanf("%d%d",&n,&m)!=EOF){memset(a,0,sizeof(a));mm=n/m;for(i=1;i<=n;i++){scanf("%d",&k);a[k]++;}int sum=0;for(i=1;i<=m;i++){if(a[i]<mm){sum+=mm-a[i];}}printf("%d\n",sum);}return 0;}
- Lottery (水题)
- Lottery
- HDU 2985 Another lottery(水题)
- 彩票问题(lottery drawing)
- hdoj 1099 Lottery(期望)
- UVA 10325 - The Lottery ( 容斥 )
- UVA10325 The Lottery(容斥原理)
- UVA10325:The Lottery (容斥)
- (每日一java) Lottery(72页)
- HDU1099————Lottery HDU(86)
- TopCoder——Lottery(买彩票问题)
- uva 10325 The Lottery(组合数学-容斥原理)
- UVA 10325 The Lottery(组合+容斥)
- UVA 10325 The Lottery(容斥原理)
- UVA 10325 The Lottery(容斥原理)
- UVA 10325 The Lottery( 容斥原理)
- On Lottery
- Another lottery
- 项目3(2)
- 《设计模式》之装饰者模式
- 学习笔记之数据结构与算法(二)
- 【OJ】QUST 1226
- mac下抓包
- Lottery (水题)
- Android 滑动菜单的实现
- Java语言基础(一)
- jQuery.extend 函数详解
- json 文件转换成 模型数据
- HDOJ 1950 Bridging signals(LIS nlogn)
- 两道面试题:2012年10月9号阿里巴巴笔试
- hdoj 1034 Candy Sharing Game【基础题】&&【关键是理解题意】
- poj 2151 01背包