CodeForces 723C Polycarp at the Radio (题意题+暴力)
题意:给定 n 个数,让把某一些变成 1-m之间的数,要改变最少,使得1-m中每个数中出现次数最少的尽量大。
析:这个题差不多读了一个小时吧,实在看不懂什么意思,其实并不难,直接暴力就好,n m不大。很明显最后1-m中次数最长的应该是n/m,
所以我们把大于n/m的都变成小于等于的,把这 n 个数中大于 m 的也变成,但是并不需要都变,只要满足每个数都是大于等于n/m就好了。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 2e3 + 5;
const LL mod = 1e9 + 7;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
inline int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} int a[maxn], b[maxn]; int main(){
while(scanf("%d %d", &n, &m) == 2){
memset(b, 0, sizeof b);
for(int i = 1; i <= n; ++i){
scanf("%d", a+i);
if(a[i] <= m) ++b[a[i]];
} int ans1 = n / m;
int ans2 = 0; int cnt = 1;
for(int i = 1; i <= n; ++i) if(a[i] <= m && b[a[i]] > ans1){
--b[a[i]];
for(int j = cnt; j <= m; ++j){
if(b[j] < ans1) { ++b[j]; cnt = j; a[i] = j; ++ans2; break; }
}
}else if(a[i] > m){
for(int j = cnt; j <= m; ++j){
if(b[j] < ans1) { ++b[j]; cnt = j; a[i] = j; ++ans2; break; }
}
} printf("%d %d\n", ans1, ans2);
for(int i = 1; i <= n; ++i)
if(i == 1) printf("%d", a[i]);
else printf(" %d", a[i]);
printf("\n");
}
return 0;
}
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 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 659F Polycarp and Hay 并查集
链接 Codeforces 659F Polycarp and Hay 题意 一个矩阵,减小一些数字的大小使得构成一个连通块的和恰好等于k,要求连通块中至少保持一个不变 思路 将数值从小到大排序,按顺 ...
- Codeforces Round #310 (Div. 2)--A(简单题)
http://codeforces.com/problemset/problem/556/A 题意:给一个01字符串,把所有相邻的0和1去掉,问还剩下几个0和1. 题解:统计所有的0有多少个,1有多少 ...
- CodeForces - 669D Little Artem and Dance 想法题 多余操作
http://codeforces.com/problemset/problem/669/D 题意:n个数1~N围成一个圈.q个操作包括操作1:输入x, 所有数右移x.操作2:1,2位置上的数(swa ...
- Codeforces 659F Polycarp and Hay【BFS】
有毒,自从上次选拔赛(哭哭)一个垃圾bfs写错之后,每次写bfs都要WA几发...好吧,其实也就这一次... 小白说的对,还是代码能力不足... 非常不足... 题目链接: http://codefo ...
- Codeforces Round #609 (Div. 2)前五题题解
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...
- CodeForces 1005D Polycarp and Div 3(思维、贪心、dp)
http://codeforces.com/problemset/problem/1005/D 题意: 给一个仅包含数字的字符串,将字符串分割成多个片段(无前导0),求这些片段里最多有多少是3的倍数 ...
随机推荐
- [Usaco2006 Nov]Bad Hair Day 乱发节
Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 1268 Solved: 625[Submit][Status][Discuss] Description ...
- Python基础之 一 字符编码及转换
python2 / python3编码转换 先上图一张: 说明:python编码转换的流程是 先进行decode解码,然后进行encode编码 解释: u'你好' -->带u表示为unicod ...
- 【网络】TCP的拥塞控制
一.拥塞控制的一般原理 拥塞:对网络中某一资源的需求超过了该资源所能提供的可用部分 拥塞控制是防止过多的数据注入到网络,这样可以使网络中的路由器或链路不致过载,拥塞控制是一个全局性的过程. 流量控制往 ...
- Linux集群的总结和思考
前言:在涉及到对外项目,经手许多小中型网站的架构,F5.LVS及Nginx都比较多,我想一种比较通俗易懂的语气跟大家说明下何谓负载均衡,何谓Linux集群,帮助大家走出这个误区,真正意义上来理解它们. ...
- CentOS 7下安装Logstash ELK Stack 日志管理系统(下)
修改防火墙,对外开放tcp/5601 [root@elk elk]# firewall-cmd --permanent --add-port=5601/tcpSuccess[root@elk elk] ...
- Struts2之struts2标签库了解和使用
一.学习案例:通过演示项目了解和使用struts2的标签库. 二.案例分析:演示项目是我当初跟着马士兵老师的视频学习时关于标签的项目,里面都有凝视,大家执行了解下. 在此我仅仅解说下经常使用的标签. ...
- MySQL运行计划不准确 -概述
为毛 MySQL优化器的运行计划 好多时候都不准确,不是最优的呢(cpu+io)??? 因素太多了:: 存在information_schema的信息是定期刷新上去的,好多时候不是最真的,甚至相差好大 ...
- [读书笔记]《没人会告诉你的PPT真相》
这本书分了三部分.第一部分偏重于基础技能,其中分为三部分,打印.放映.保存.第二部分是进阶,分为模板下载.模板修改.增加自定义页面等.第三部分是打造商业范的PPT,分为商业范的特征,具体技能体现(重复 ...
- asp.net项目与开源单点登录项目CAS的结合
这段时间搞的一个asp.net mvc项目,采用了单点登录. 这个单点登录就是CAS,一个开源的JAVA项目.当然,这并不影响ASP.NET项目结合它来进行登录.因为各自分工不同:单点登录(管它是不是 ...
- 用javascript写一个前端等待控件
前端等待控件有啥新奇的?什么jquery啦,第三方控件啦,好多好多,信手拈来. 因为项目使用了bootstrap的原因,不想轻易使用第三方,怕不兼容.自己写一个. 技术点包括动态加载CSS,javas ...