CodeForces 723C Polycarp at the Radio (贪心+暴力)
来源:互联网 发布:linux exec用法 编辑:程序博客网 时间:2024/05/01 18:13
题意:给定 n 个数,让把某一些变成 1-m之间的数,要改变最少,使得1-m中每个数中出现次数最少的尽量大。
虽然这个贪心挺好想到的,但是却不是那么容易敲出来。。。
看别人的代码,真好。。
int a[N];int cnt[N];int main(){ int n,m; sf("%d%d",&n,&m); int ans1=n/m,ans2=0; rep(i,1,n){ sf("%d",&a[i]); if(a[i]<=m){ cnt[a[i]]++; } } for(int i=1;i<=n;++i){ if(a[i]>m||a[i]<=m&&cnt[a[i]]>ans1){ for(int j=1;j<=m;++j){ if(cnt[j]<ans1){ if(a[i]<=m){ cnt[a[i]]--; } a[i]=j; cnt[j]++; ans2++;break; } } } } pf("%d %d\n",ans1,ans2); rep(i,1,n){ pf("%d%c",a[i],i==n?'\n':' '); }}
阅读全文
0 0
- CodeForces 723C Polycarp at the Radio (贪心+暴力)
- Codeforces 723 C. Polycarp at the Radio
- Codeforces 723C.Polycarp at the Radio
- Codeforces Round#375 C:Polycarp at the Radio(贪心)
- [贪心] Codeforces 723C #375 (Div. 2) C. Polycarp at the Radio
- CodeForces 723C-Polycarp at the Radio(模拟 贪心 vector乱搞)
- 【23.48%】【codeforces 723C】Polycarp at the Radio
- codeforces 723C. Polycarp at the Radio [模拟]【杂类】
- 【codeforces 723 C】【暴力】C. Polycarp at the Radio【1~m中最少的数尽量多】
- codeforces Polycarp at the Radio
- codefroces 723c Polycarp at the Radio
- Codeforce 723C - Polycarp at the Radio
- Codeforces Round #375 (Div. 2) C. Polycarp at the Radio(贪心)
- Codeforces Round #375 (Div. 2) C. Polycarp at the Radio 贪心+排序
- Codeforces Round #375 (Div. 2) C. Polycarp at the Radio 贪心
- C. Polycarp at the Radio
- [codeforces] C. Polycarp at the Radio 数组统计
- Codeforces Round #375 (Div. 2)-C. Polycarp at the Radio
- IMPDP命令
- Flink入门教程--Jobs and Scheduling(任务和调度)
- 笔记:linux下查询网络端口被监听的信息方法。
- spfa算法
- 解决jsp上传文件,重启tomcat后文件和文件夹自动删除
- CodeForces 723C Polycarp at the Radio (贪心+暴力)
- think in java第十六章数组 总结随笔
- diff.js 列表对比算法 源码分析
- HDU 6199 gems gems gems dp
- org.mybatis.spring.MyBatisSystemException
- python3 如何实现python2 中cmp()函数的功能
- 关于intern和字符串
- Python--脚本自动发送邮件
- java容器,java框架