C. Polycarp at the Radio
来源:互联网 发布:ubuntu 17.04 163源 编辑:程序博客网 时间:2024/05/17 05:11
这题题意不太好理解,但是可以通过样例推。主要考察思维的全面性,注意把b[m]特殊处理下。
AC代码:
#include<cstdio>#include<cstring>const int maxn=2000+5;int cnt[maxn],play[maxn];int main(){ int n,m; scanf("%d%d",&n,&m); memset(cnt,0,sizeof(cnt)); for(int i=1;i<=n;++i){ scanf("%d",&play[i]); if(play[i]<=m) { cnt[play[i]]++; } } //确定goal int goal=n/m; int change=0; if(cnt[m]>goal){ //处理m for(int i=1;i<=n&&cnt[m]>goal;++i){ if(play[i]==m){ for(int j=1;j<m;++j){ if(cnt[j]<goal) { change++; cnt[m]--; cnt[j]++; play[i]=j; break; } } } } } for(int i=1;i<=m;++i){ if(cnt[i]<goal){ for(int j=1;j<=n&&cnt[i]<goal;++j){ int u=play[j]; if(u>m||cnt[u]>goal){ change++; cnt[i]++; if(u<=m) cnt[u]--; play[j]=i; } } } } printf("%d %d\n",goal,change); for(int i=1;i<=n;++i){ if(i==1) printf("%d",play[i]); else printf(" %d",play[i]); } printf("\n"); return 0;}
如有不当之处欢迎指出!!
0 0
- C. Polycarp at the Radio
- codefroces 723c Polycarp at the Radio
- Codeforces 723 C. Polycarp at the Radio
- Codeforces 723C.Polycarp at the Radio
- Codeforce 723C - Polycarp at the Radio
- [codeforces723C]Polycarp at the Radio
- CF_C. Polycarp at the Radio
- codeforces Polycarp at the Radio
- [codeforces] C. Polycarp at the Radio 数组统计
- Codeforces723 C. Polycarp at the Radio (模拟)
- 【23.48%】【codeforces 723C】Polycarp at the Radio
- Codeforces Round #375 (Div. 2)-C. Polycarp at the Radio
- codeforces 723C. Polycarp at the Radio [模拟]【杂类】
- Codeforces Round#375 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 723C Polycarp at the Radio (贪心+暴力)
- codeforces723C- Polycarp at the Radio-greedy
- Handlebars.js 预编译
- linux基础第一课
- typeof 的用法和用处
- ansys工作平面平移转动
- OpenCL实现序列卷积
- C. Polycarp at the Radio
- JAVA基本语法注意事项总结
- OJ-上海交大-1021. 从前有座山
- 2.第一个小程序(微信公众号开发实战)
- codeforces281CRectangle Puzzle+矩形旋转+面积交
- 289. Game of Life
- LayoutInflater的inflate()函数解释
- String类探讨
- c# windows小程序manager