C. Polycarp at the Radio
这题题意不太好理解,但是可以通过样例推。主要考察思维的全面性,注意把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;
}
如有不当之处欢迎指出!!
C. 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 ...
- cf723c Polycarp at the Radio
Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be re ...
- 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 ...
- 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不大. ...
随机推荐
- js设置滚动条位置
JS控制滚动条的位置: window.scrollTo(x,y); 竖向滚动条置顶(window.scrollTo(0,0); 竖向滚动条置底 window.scrollTo(0,document.b ...
- 02-Go语言数据类型与变量
Go基本类型 布尔型: bool - 长度: 1字节 - 取值范围: true,false - 注意事项: 不可以用数字代表true或false 整型: int/uint - 根据运行平台可能为32或 ...
- TCP全连接队列和半连接队列已满之后的连接建立过程抓包分析[转]
最近项目需要做单机100万长连接与高并发的服务器,我们开发完服务器以后,通过自己搭的高速压测框架压测服务端的时候,发生了奇怪的现象,就是服务端莫名其妙的少接收了连接,造成了数据包的丢失,通过网上查资料 ...
- 2. getline()和get()
1.面向行输入:getline() ---其实还可以接受第三个参数. getline()函数读取整行,调用该方法 使用cin.getline().该函数有两个参数, 第一个参数是是用来存储输入行的数组 ...
- Django的admin.py注册流程
通常创建一个Django项目的时候,在Django的配置文件settings.py中,都会有下面的这段配置: INSTALLED_APPS = [ 'django.contrib.admin', 'd ...
- Trusted Execution Technology (TXT) --- 度量(Measurement)篇
版权声明:本文为博主原创文章,未经博主允许不得转载.http://www.cnblogs.com/tsec/p/8413537.html 0. 导读 TXT基本原理篇介绍了TXT安全度量的基本概念,包 ...
- 不使用Math.random实现随机数
不使用Math.random实现随机数 var rand = (function(){ var today = new Date(); var seed = today.getTime(); func ...
- MySQL递归的替代方案
类似查出某个机构下所有的子机构,可用递归的方式实现.但MySQL不支持递归,可以考虑用如下的方式来实现递归调用. 第一种,临时表方式,使用函数每次查出子机构,再可以和其他表联查. 第二种,新建一张表, ...
- WebService的学习
这篇文章不错,直接转了 http://blog.csdn.net/terryzero/article/details/5976638#comments
- CF 455D. Serega and Fun [分块 deque]
Serega and Fun 题意: [l,r]循环右移一位,查询区间内某个数出现次数 为什么好多人用链表?反正我是不会写双向链表 完全可以分块然后模拟啊...中间的块只会插入删除一个元素呀....用 ...