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不大. ...
随机推荐
- easyUI中点击datagrid列标题排序
easyUI中点击datagrid的排序有两种,一种是本地的,一种是服务器的.本地的只能排序当前页,而服务器的可以对全部页进行排序.这里主要是分享下服务器排序. 1.为datagrid添加属性remo ...
- 【转】国际GNSS服务组织IGS
国际GNSS服务组织The International GNSS Service,简称IGS,前身为国际GPS服务组织.IGS提供的高质量数据和产品被用于地球科学研究等多个领域. IGS组织由卫星跟踪 ...
- 你可能不知道的.Net Core Configuration
目录 执行原理 环境变量 Spring Cloud Config Server 挂卷Volume Config Server vs Volume 执行原理 1. 配置读取顺序:与代码先后顺序一致. p ...
- 取IP的几个方法
ifconfig eth0|grep " inet add"|cut -d":" -f2|cut -d " " -f1 ifconfig e ...
- Jmeter之性能测试类型
pipe-clean test 在测试环境预先跑 确定脚本准确性 单用户跑 获取baseline 容量测试 经典的性能测试类型 获取系统稳定运行时最大的吞吐量/并发数/响应时间时 尽量模拟真实情况 ...
- python3中,os.path模块下常用的用法总结
abspath basename dirname exists getatime getctime getmtime getsize isabs isdir isfile islink ismount ...
- 小白学Docker之Compose
承接上篇文章:小白学Docker之基础篇,自学网站来源于https://docs.docker.com/get-started 概念 Compose是一个编排和运行多容器Docker应用的工具,主要是 ...
- python多线程限制并发数示例
#coding: utf-8 #!/usr/bin/env python import Queue import threading import time prolock = threading.L ...
- IIS 加载 JSON 错误 404 解决办法
MIME设置:在IIS的站点属性的HTTP头设置里,选MIME 映射中点击”文件类型”-”新类型”,添加一个文件类型:关联扩展名:*.json内容类型(MIME):application/x-java ...
- BZOJ 1492: [NOI2007]货币兑换Cash [CDQ分治 斜率优化DP]
传送门 题意:不想写... 扔链接就跑 好吧我回来了 首先发现每次兑换一定是全部兑换,因为你兑换说明有利可图,是为了后面的某一天两种卷的汇率差别明显而兑换 那么一定拿全利啊,一定比多天的组合好 $f[ ...