CodeForces 723C Polycarp at the Radio (贪心+暴力)
2017-09-12 11:49
507 查看
题意:给定 n 个数,让把某一些变成 1-m之间的数,要改变最少,使得1-m中每个数中出现次数最少的尽量大。
虽然这个贪心挺好想到的,但是却不是那么容易敲出来。。。
看别人的代码,真好。。
int a ; int cnt ; 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':' '); } }
相关文章推荐
- CodeForces 723C Polycarp at the Radio (题意题+暴力)
- CodeForces 723C-Polycarp at the Radio(模拟 贪心 vector乱搞)
- 【Codeforces 723C】Polycarp at the Radio 贪心
- Codeforces 723C.Polycarp at the Radio
- [贪心] Codeforces 723C #375 (Div. 2) C. Polycarp at the Radio
- codeforces 723C. Polycarp at the Radio [模拟]【杂类】
- codeforces 723C : Polycarp at the Radio
- 【23.48%】【codeforces 723C】Polycarp at the Radio
- 【codeforces 723 C】【暴力】C. Polycarp at the Radio【1~m中最少的数尽量多】
- codeforces723C- Polycarp at the Radio-greedy
- Codeforces 723 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(贪心)
- Codeforces Round #375 (Div. 2) C. Polycarp at the Radio 贪心
- Codeforces Round #375 (Div. 2) Polycarp at the Radio 优先队列模拟题 + 贪心
- Codeforce 723C - Polycarp at the Radio
- Codeforces Round#375 C:Polycarp at the Radio(贪心)
- cf-723C Polycarp at the Radio
- CodeForces723C Polycarp at the Radio 贪心
- Codeforces Round #375 (Div. 2) C. Polycarp at the Radio 贪心