cf723c Polycarp at the Radio
Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence a1, a2, ..., an, where ai is a band, which performs the i-th song. Polycarp likes bands with the numbers from 1 to m, but he doesn't really like others.
We define as bj the number of songs the group j is going to perform tomorrow. Polycarp wants to change the playlist in such a way that the minimum among the numbers b1, b2, ..., bm will be as large as possible.
Find this maximum possible value of the minimum among the bj (1 ≤ j ≤ m), and the minimum number of changes in the playlist Polycarp needs to make to achieve it. One change in the playlist is a replacement of the performer of the i-th song with any other group.
The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 2000).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the performer of the i-th song.
In the first line print two integers: the maximum possible value of the minimum among the bj (1 ≤ j ≤ m), where bj is the number of songs in the changed playlist performed by the j-th band, and the minimum number of changes in the playlist Polycarp needs to make.
In the second line print the changed playlist.
If there are multiple answers, print any of them.
4 2
1 2 3 2
2 1
1 2 1 2
7 3
1 3 2 2 2 2 1
2 1
1 3 3 2 2 2 1
4 4
1000000000 100 7 1000000000
1 4
1 2 3 4
In the first sample, after Polycarp's changes the first band performs two songs (b1 = 2), and the second band also performs two songs (b2 = 2). Thus, the minimum of these values equals to 2. It is impossible to achieve a higher minimum value by any changes in the playlist.
In the second sample, after Polycarp's changes the first band performs two songs (b1 = 2), the second band performs three songs (b2 = 3), and the third band also performs two songs (b3 = 2). Thus, the best minimum value is 2.
/*
给一个数列,代表每每首歌谁负责唱,要让前m个歌手中演唱曲数最少的最多,求一个最少修改次数
贪心即可,so water
*/
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = ;
int n,m,b[maxn],a[maxn],cge[maxn][maxn],cge_a[maxn];
int ans1,ans2;
int cnt = ,t;
int main(){
cin>>n>>m;
for(int i = ;i <= n;i++){
cin>>a[i];
if(a[i] <= m) b[a[i]]++;
}
ans1 = n / m;
for(int i = ;i <= n;i++){
while(b[cnt] >= ans1) cnt++;
if(cnt > m) break;
if(a[i] > m){
a[i] = cnt;
b[cnt]++;
ans2++;
}
}
for(int i = ;i <= m;i++){
while(b[i] > ans1){
while(b[cnt] >= ans1) cnt++;
if(cnt > m) break;
b[i]--;
cge_a[i]++;
cge[i][cge_a[i]] = cnt;
b[cnt]++;
ans2++;
}
if(cnt > m) break;
}
cout<<ans1<<" "<<ans2<<endl;
for(int i = ;i <= n;i++){
if(a[i] <= m)if(cge_a[a[i]]){
t = a[i];
a[i] = cge[t][cge_a[t]];
cge_a[t]--;
}
cout<<a[i]<<" ";
}
return ;
}
cf723c Polycarp at the Radio的更多相关文章
- Codeforces 723C. Polycarp at the Radio 模拟
C. Polycarp at the Radio time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...
- Codeforces Round #375 (Div. 2) C. Polycarp at the Radio 贪心
C. Polycarp at the Radio time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- codeforces 723C : Polycarp at the Radio
Description Polycarp is a music editor at the radio station. He received a playlist for tomorrow, th ...
- 【23.48%】【codeforces 723C】Polycarp at the Radio
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【Codeforces 723C】Polycarp at the Radio 贪心
n个数,用最少的次数来改变数字,使得1到m出现的次数的最小值最大.输出最小值和改变次数以及改变后的数组. 最小值最大一定是n/m,然后把可以改变的位置上的数变为需要的数. http://codefor ...
- C. Polycarp at the Radio
这题题意不太好理解,但是可以通过样例推.主要考察思维的全面性,注意把b[m]特殊处理下. AC代码: #include<cstdio> #include<cstring> co ...
- codeforces723----C. Polycarp at the Radio
//AC代码...表示很晕 #include <iostream> using namespace std; ],b[]; int main() { int n,m,cnt; cin &g ...
- Codeforces Round #375 (Div. 2) Polycarp at the Radio 优先队列模拟题 + 贪心
http://codeforces.com/contest/723/problem/C 题目是给出一个序列 a[i]表示第i个歌曲是第a[i]个人演唱,现在选出前m个人,记b[j]表示第j个人演唱歌曲 ...
- CodeForces 723C Polycarp at the Radio (题意题+暴力)
题意:给定 n 个数,让把某一些变成 1-m之间的数,要改变最少,使得1-m中每个数中出现次数最少的尽量大. 析:这个题差不多读了一个小时吧,实在看不懂什么意思,其实并不难,直接暴力就好,n m不大. ...
随机推荐
- monkeyrunner之坐标或控件ID获取方法(六)
Monkeyrunner的环境已经搭建完成,现在对Monkeyrunner做一个简介. Monkeyrunner工具提供了一套API让用户/测试人员来调用,调用这些api可以控制一个Android设备 ...
- 【2016-10-20】【坚持学习】【Day10】【反射2】
Type类的属性: Name 数据类型名 FullName 数据类型的完全限定名(包括命名空间名) Namespace 定义数据类型的命名空间名 ...
- node基础11:接受参数
1.接收参数 在Node中接受GET/POST请求的参数不像PHP那样,在PHP中直接有全局变量$_GET,$_POST来接受url,或者请求体重的参数. 在node中接受GET参数使用url.par ...
- C#中TransactionScope的使用方法和原理
在.net 1.1的时代,还没有TransactionScope类,因此很多关于事务的处理,都交给了SqlTransaction和SqlConnection,每个Transaction是基于每个Con ...
- java并发编程学习: 守护线程(Daemon Thread)
在正式理解这个概念前,先把 守护线程 与 守护进程 这二个极其相似的说法区分开,守护进程通常是为了防止某些应用因各种意外原因退出,而在后台独立运行的系统服务或应用程序. 比如:我们开发了一个邮件发送程 ...
- IoC 与 AOP (谈谈你对 Spring 的理解)
一.Spring 实现了工厂模式的工厂类,这个类名为BeanFactory(实际上是一个接口),在程序中通常 BeanFactory 的子类 ApplicationContext. Spring相当于 ...
- Mongodb学习笔记二(Mongodb基本命令)
第二章 基本命令 一.Mongodb命令 说明:Mongodb命令是区分大小写的,使用的命名规则是驼峰命名法. 对于database和collection无需主动创建,在插入数据时,如果databas ...
- 备忘:spring jdbc事务代码 mybatis, nhibernate
http://files.cnblogs.com/files/mikelij/mymavenMar1.rar
- 当泛型方法推断,扩展方法遇到泛型类型in/out时。。。
说到泛型方法,这个是.net 2.0的时候引入的一个重要功能,c#2.0也对此作了非常好的支持,可以不需要显试的声明泛型类型,让编译器自动推断,例如: void F<T>(T value) ...
- jQuery之Ajax--辅助函数
1.这些函数用于辅助完成Ajax任务. 2. jQuery.param()方法:创建一个数组或对象序列化的的字符串,适用于一个URL 地址查询字符串或Ajax请求. 我们可以显示一个对象的查询字 ...