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_10_dom表单
事件的优先级? 先执行事件,后执行标签内置事件,如果事件返回false不执行后面的事件或标签内置事件 如何通过js提交表单? 任意标签定义onclick事件 函数中写入:document.getEle ...
- xml格式字符串转为Map
import org.dom4j.Document;import org.dom4j.DocumentException;import org.dom4j.Element;import org.dom ...
- Python用户输入和代码注释
一.用户输入 若你安装的是Python3.x版本,当你在Python IDLE(编辑器) 中输入以下代码: name = input('用户名:') print('Hello',name) 保存并执行 ...
- IO (二)
1 字符流的缓冲区 缓冲区的出现提高了对数据的读写效率. 对应的类: BufferedWriter BufferedReader 缓冲区要结合流才能使用. 在流的基础上对流的功能进行了增强. 2 Bu ...
- 【转】C++易混知识点1: 指针常量和常量指针的区别,附有详细案例解释
熟悉C++也已经有一些年头了,今天突然翻出当年浏览的书籍,对一些概念居然生疏了,指针常量和常量指针由于 指针 这一特殊的对象而变得难以区别.因此,在思考再三之后,决定写下该篇总结,加强对他们的区别: ...
- Notepad++运行Java
插件NppExec使用 首先要让Notepad++编译和运行Java,前提是电脑里已经配置好了Java的环境 1,安装插件NppExec:解压出来提取NppExec.dll文件放在Notepad++安 ...
- iozone测试磁盘性能
什么是iozone? iozone是一个文件系统的benchmark工具,可以测试不同的操作系统中文件系统的读写性能. 可以测试 Read, write, re-read,re-write, read ...
- mysql备份
工具 mysql mysqldump 应用举例 导出 命令行下具体用法如下: mysqldump -u用戶名 -p密码 -d 数据库名 表名 脚本名; 1.导出数据库为dbname的表结构(其中用戶名 ...
- PostgreSQL版本快速升级
PostgreSQL版本快速升级 写在前面 PostgreSQL9.5版本支持数据分片的功能,为以后做分布式考虑,准备将生产环境的9.1版本升级至9.5.中间需要做数据迁移. 在迁移操作中,为保证数据 ...
- BZOJ 1854: [Scoi2010]游戏 [连通分量 | 并查集 | 二分图匹配]
题意: 有$n \le 10^6$中物品,每种两个权值$\le 10^4$只能选一个,使得选出的所有权值从1递增,最大递增到多少 一开始想了一个奇怪的规定流量网络流+二分答案做法...然而我还不知道怎 ...