【Codeforces 723C】Polycarp at the Radio 贪心
n个数,用最少的次数来改变数字,使得1到m出现的次数的最小值最大。输出最小值和改变次数以及改变后的数组。
最小值最大一定是n/m,然后把可以改变的位置上的数变为需要的数。
http://codeforces.com/problemset/problem/723/C
4 2
1 2 3 2
2 1
1 2 1 2
7 3
1 3 2 2 2 2 1
2 1
1 3 3 2 2 2 1
4 4
1000000000 100 7 1000000000
1 4
1 2 3 4
#include<bits/stdc++.h>
using namespace std;
int n,m,a[];
int pos[],cnt;
int cha[];
int ans,ans2;
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
ans=n/m;
printf("%d ",ans); for(int i=;i<=m;i++){
int num=;
int j;
for(j=;j<=n;j++){
if(a[j]==i){
num++;
pos[j]=;//代表j位置不能改变
}
if(num==ans)break;
}
if(num<ans){cha[i]=ans-num;ans2+=cha[i];}
}
int j=;
for(int i=;i<=m;i++){
for(int k=;k<cha[i];k++){
while(pos[j])j++;
a[j++]=i;
}
}
printf("%d\n",ans2);
for(int i=;i<=n;i++)
printf("%d ",a[i]);
}
【Codeforces 723C】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 723C : Polycarp at the Radio
Description Polycarp is a music editor at the radio station. He received a playlist for tomorrow, th ...
- CodeForces 723C Polycarp at the Radio (题意题+暴力)
题意:给定 n 个数,让把某一些变成 1-m之间的数,要改变最少,使得1-m中每个数中出现次数最少的尽量大. 析:这个题差不多读了一个小时吧,实在看不懂什么意思,其实并不难,直接暴力就好,n m不大. ...
- 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 ...
- Codeforces 437C The Child and Toy(贪心)
题目连接:Codeforces 437C The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...
- Codeforces Round #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
- Codeforces 659F Polycarp and Hay 并查集
链接 Codeforces 659F Polycarp and Hay 题意 一个矩阵,减小一些数字的大小使得构成一个连通块的和恰好等于k,要求连通块中至少保持一个不变 思路 将数值从小到大排序,按顺 ...
- 【23.48%】【codeforces 723C】Polycarp at the Radio
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 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个人演唱歌曲 ...
随机推荐
- uwsgi+flask环境中安装matplotlib
uwsgi+flask的python有自身的virtual environment,可以通过如下命令进入 . venv/bin/activate 虽然通过sudo apt-get install py ...
- 应用多个icon的对比
在给应用设计图标的时候,可能会遇到这样的需求,应用图标有老版和新版两种,而又想在桌面上同时显示这两个图标以对比效果. 一个应用本身只有一个自己的icon,在AndroidManifest.xml文件中 ...
- 分享一例测试环境下nginx+tomcat的视频业务部署记录
需求说明:在测试环境下(192.168.1.28)部署一套公司某业务环境,其中:该业务前台访问地址: http://testhehe.wangshibo.com该业务后台访问地址: http://te ...
- 初识html5 File API实现带有进度提示的文件上传
Html5终于解决了上传文件的同时显示文件上传进度的老问题.现在大部分的网站用Flash去实现这一功能,还有一些网站继续采用Html <form>with enctype=multipar ...
- AAL模版 中英文对照
来源:http://52brain.com/thread-17336-1-1.html Brodmann分区是一个根据细胞结构将大脑皮层划分为一系列解剖区域的系统.神经解剖学中所谓细胞结构(Cytoa ...
- JavaScript弹出窗口技巧
window.open ('faces/newPage.jsp','newwindow','height=300,width=700, top=50,left=50,toolbar=no,menuba ...
- mac里git项目删除.DS_Store文件
用mac开发项目,每次提交文件时都生成修改文件的.DS_Store文件,提交时会不会觉得比较烦?别急,下面给出解决方案.我们需要用到.gitignore文件去配置Git目录中需要忽略的文件. .git ...
- Oracle 数据库日常巡检
1. 检查数据库基本状况 包含:检查Oracle实例状态,检查Oracle服务进程,检查Oracle监听进程,共三个部分. 1.1. 检查Oracle实例状态 select instance_name ...
- lecture9-提高模型泛化能力的方法
HInton第9课,这节课没有放论文进去.....如有不对之处还望指正.话说hinton的课果然信息量够大.推荐认真看PRML<Pattern Recognition and Machine L ...
- .html 、.htm 、 .shtml 以及 .shtm 四种扩展名的文件区别
新增了一个分类,叫做 Personals,中文我把它解释成 "个人恶趣味",这里将记载一些对工作无关紧要,但是个人又一时有兴趣了解的东西. 今天要讲的是如题的 4 种扩展文件的区别 ...