【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个人演唱歌曲 ...
随机推荐
- 在Eclipse彻底删除一个项目
1. 先必须关闭项目 2. 再从workspace中把项目删除
- 一个App需要的东西
1.短信申请平台 (发送验证码需要的短信) http://www.yuntongxun.com/api/sms?nl=sy_cp 容联云通讯
- MMDrawerController的使用
1.http://www.jianshu.com/p/9e55cbf7d5ab MMDrawerController的使用
- Func<T,TResult>泛型委托
描述: 封装一个具有一个参数并返回TResult参数指定的类型值的方法. 语法: public delegate TResult Func<T,TResult>(T arg); 参数类型: ...
- 设置root用户不保存终端历史记录到.bash_history
在.bashrc的最后行追加 unset HISTFILE cat .bash_history 还能看到 unset HISTFILE 之前保留的命令unset HISTFILE 之后的命令不会保留, ...
- [转]RabbitMQ消息队列在PHP下的应用
FROM : http://www.cnblogs.com/phpinfo/p/4104551.html 参考资料: http://www.yuansir-web.com/tag/rabbitmq/ ...
- Cordova - 使用Cordova开发iOS应用实战2(生命周期、使用Safari调试)
Cordova - 使用Cordova开发iOS应用实战2(生命周期.使用Safari调试) 前文我们创建了一个简单的Cordova项目,结构如下: 1,Cordova生命周期事件 (1)device ...
- tkinter 的两个例子
第一个例子:after 用于定时操作 import tkinter as tk import time class MyApp(tk.Frame): def __init__(self, msecs= ...
- TinyFrame升级之三:逻辑访问部分
在上一篇,我们打造了自己的数据访问部分,这篇,我们准备讲解如何打造逻辑访问部分. 在上一篇中,我们利用Repository模式构建了基于泛型的操作合集.由于这些操作的合集都是原子性的操作,也就是针对单 ...
- Java7并发编程实战(一) 线程的等待
试想一个情景,有两个线程同时工作,还有主线程,一个线程负责初始化网络,一个线程负责初始化资源,然后需要两个线程都执行完毕后,才能执行主线程 首先创建一个初始化资源的线程 public class Da ...