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 21 2 3 2
2 11 2 1 2
7 31 3 2 2 2 2 1
2 11 3 3 2 2 2 1
4 41000000000 100 7 1000000000
1 41 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 = 3005; int n,m,b[maxn],a[maxn],cge[maxn][maxn],cge_a[maxn]; int ans1,ans2; int cnt = 1,t; int main(){cin>>n>>m;for(int i = 1;i <= n;i++){cin>>a[i];if(a[i] <= m) b[a[i]]++;}ans1 = n / m;for(int i = 1;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 = 1;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 = 1;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 0; }
转载于:https://www.cnblogs.com/hyfer/p/5929949.html
cf723c Polycarp at the Radio相关推荐
- cf-723C Polycarp at the Radio
cf-723C Polycarp at the Radio 题目点击打开链接 http://codeforces.com/contest/723/problem/C 分析:先定义每个数字在数组中出现 ...
- 【Codeforces】Round #375 (Div. 2)
Position:http://codeforces.com/contest/723 我的情况 啊哈哈,这次raiting肯定要涨,接受过上次的教训,先用小号送肉,大号都是一发切,重回蓝咯 结果... ...
- 2016区域赛前冲刺训练
UPD 2016.10.23 shift-and (2题) Codeforces 训练 现在已经完成了: 191 [Codeforces Round #377] (6/6) Div 2 A Buy a ...
- linux touch命令对于windows,Windows代替touch命令
codeforces 723C : Polycarp at the Radio Description Polycarp is a music editor at the radio station. ...
- CSS3重新定义input中呆若木鸡的默认复选框CheckBox和单选框Radio样式
<!DOCTYPE html> <html> <head><meta charset="UTF-8"><style>/* ...
- thymeleaf : input/select/radio回显
thymeleaf中不用自己去写checked="checked" selected="selected"这种代码,他自己会选. input <input ...
- 解决:angularjs radio默认选中失效问题
添加ng-model后checked="checked"失效,可见angularjs也不好,会失效html标准属性 解决:添加ng-checked="1" &l ...
- html中radio、checkbox选中状态研究(静下心来看,静下心来总结)
html中radio.checkbox选中状态研究(静下心来看,静下心来总结) 一.总结 1.单选框的如果有多个checked 会以最后一个为准 2.js动态添加checked属性:不行:通过 $(& ...
- radio根据name 获取选中值及判断是否被选中
$('input:radio[name="fjscfs"]:checked').val(); 根据id判断是否被选中 if($("#A26").is(" ...
最新文章
- HDU 1047 Integer Inquiry( 高精度加法水 )
- 【转】android自定义控件
- SD-关于定价日期的设置
- 看雪学院课程《汇编语言详解与二进制漏洞初阶》笔记
- 抛弃鼠标的神器——Vimium
- 图片加载------reactVirtualized
- 6-2 是否二叉搜索树 (25 分)
- vue的自定义指令的坑
- 五大主流浏览器内核的源起以及国内各大浏览器内核总结
- 关于光的波粒二象性的解释--答复年少时的疑惑
- 无法打开ONEDRIVE的解决方法【等待验证】
- 国产超级英雄逆袭好莱坞
- omf多路径 oracle_Oracle数据库使用OMF来简化数据文件的管理
- 高级验证方法学()-Mentor-笔记
- 薛非的个人资料编程c语言,上海启航考研英语薛非老师
- 《大数据项目实战之搜索引擎用户行为分析》
- Java方法详解(基础)
- 美标C70600(BFe10-1-1)无缝管
- GZIP文件格式简介
- python编辑器哪款最好_python编辑器哪一款是比较好用的
热门文章
- 零基础掌握交互设计的重点笔记
- 智能增效,路路通软件为中金骨质瓷发展再添新动能!
- C++函数指针定义及用法
- 精美到无可挑剔的几首古典音乐
- 谱聚类python代码_Python 谱聚类算法从零开始
- 在linux中tldr的用法,详解 “Tldr++” 客户端:使用 TLDR 手册 快速了解 Linux 命令...
- Go语言---动态查询数据库
- shell中获取文件夹中文件名
- Linux下提取文件夹下的所有文件名称
- 交叉熵(Cross-Entropy)