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的倍数 ...
随机推荐
- RQNOJ273 马棚问题
题目描述 每天,小明和他的马外出,然后他们一边跑一边玩耍.当他们结束的时候,必须带所有的马返回马棚,小明有K个马棚.他把他的马排成一排然后跟随它走向马棚,因为他们非常疲劳,小明不想让他的马做过多的移动 ...
- 远程连接mongodb时,27017端口连接不上的解决办法
一.背景描述: 我在linux RED7上安装了mongodb,并没有修改mongodb的配置文件.然后通过另外一台电脑用pymongo连接mongodb时,报错:timeout. ping IP ...
- Solr Admin管理界面使用说明
Notice:本说明基于Solr6.4.2. 本文讨论的是如何使用Solr Admin UI. 一级菜单 图1.SolrCloud模式 图2.单机Solr模式 Logging:展示Solr的日志,不用 ...
- 深入理解计算机操作系统——第11章:CS模型,网络
网络编程: 11.1 客户端-服务器编程模型 (1)一个应用是由一个服务器进程和一个或多个客户端进程组成. (2)服务器管理某种资源,并且操纵这种资源来为客户端服务. CS模型: CS的基本操作是事务 ...
- C. Day at the Beach---cf559
http://codeforces.com/problemset/problem/599/C 题目大意: 有n个城堡的高度 让你最多分成几个块 每个块排过序之后 整体是按照升序来的 分析: ...
- Atom编辑Markdown文件保存后行尾的空格自动消失的问题解决
Markdown文件的行尾增加两个空格表示一行结束需要换行. 但保存文件后,行尾的空格自动消失,导致不换行. 解决方法: 1.[Edit]->[Preferences]->[Package ...
- c++之NVI手法
non-virtual interface(NVI)手法:令用户通过public non-virtual成员函数间接调用private virtual函数,将这个non-virtual函数称为virt ...
- 【转】海量数据处理算法-Bloom Filter
1. Bloom-Filter算法简介 Bloom Filter(BF)是一种空间效率很高的随机数据结构,它利用位数组很简洁地表示一个集合,并能判断一个元素是否属于这个集合.它是一个判断元素是否存在于 ...
- 《javascript设计模式》读书笔记二(封装和隐藏信息)
1.为什么要封装和信息隐藏 做过编程的朋友们知道"耦合"这个词.事实上封装的效果就是为了解耦,让类和类之间没有太多的联系,防止某一天改动某一类的时候,产生"多米骨诺牌效应 ...
- 说说Android应用的persistent属性(转)
1 启动persistent应用 在Android系统中,有一种永久性应用.它们对应的AndroidManifest.xml文件里,会将persistent属性设为true,比如: <appli ...