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不大. ...
随机推荐
- CColor类封装
CColor类封装 Color.h #pragma once #include <sstream> #include <string> using namespace std; ...
- Linux指令--性能监控和优化命令相关指令
原文出处:http://www.cnblogs.com/peida/archive/2012/12/05/2803591.html.感谢作者无私分享 性能监控和优化命令相关指令有:top,free,v ...
- SVN中服务器地址变更
SVN中服务器地址变更后不需要重新导项目,只要修改下SVN的服务器地址,更新一下即可.有两种方法: 方法一:通过MyEclipse中SVN插件 1.选择window→show view→other→S ...
- 定时任务schedule(spring boot )
1. 定时任务实现方式:SpringBoot自带的Scheduled,可以将它看成一个轻量级的Quartz,而且使用起来比Quartz简单许多,本文主要介绍. 执行方式:单线程(串行)多线程(并行) ...
- 【转】用Linux命令行获取本机外网IP地址
$ curl ifconfig.me $ curl icanhazip.com $ curl ident.me $ curl ipecho.net/plain $ curl whatismyip.ak ...
- IDEA精髓快捷键
删除一行:Ctrl+X 快速查找:Ctrl+F 打开文件目录结构: Ctrl+F12 可以把代码包在一个块内:Ctrl+Alt+T 替换文本:Ctrl+R, Alt+Shift+Up/Down,上/下 ...
- oracle学习(一)
作为一个入门选手,怕忘记,所以所有东西都尽量写下来.(省略oracle11g的安装过程) 一.sqlpuls用sys账户登录 (sqlplus是客户端连上服务器的一个工具) 1.使用cmd控制台登录 ...
- 异常检测算法:Isolation Forest
iForest (Isolation Forest)是由Liu et al. [1] 提出来的基于二叉树的ensemble异常检测算法,具有效果好.训练快(线性复杂度)等特点. 1. 前言 iFore ...
- 一道python面试题引发的血案
这里说的是一道阿里校招的面试题:一行代码实现对列表a中的偶数位置的元素进行加3后求和? 今天去面试同样遇到了这个题目,这道题考察的是对python高阶函数map/filter的灵活运用(具体的使用方法 ...
- gitlab 操作指南
重置密码 https://docs.gitlab.com/ce/security/reset_root_password.html gitlab 一键安装 https://docs.gitlab.co ...