题意:给定 n 个数,让把某一些变成 1-m之间的数,要改变最少,使得1-m中每个数中出现次数最少的尽量大。

析:这个题差不多读了一个小时吧,实在看不懂什么意思,其实并不难,直接暴力就好,n m不大。很明显最后1-m中次数最长的应该是n/m,

所以我们把大于n/m的都变成小于等于的,把这 n 个数中大于 m 的也变成,但是并不需要都变,只要满足每个数都是大于等于n/m就好了。

代码如下:

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <iostream>
  7. #include <cstring>
  8. #include <set>
  9. #include <queue>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <map>
  13. #include <cctype>
  14. #include <cmath>
  15. #include <stack>
  16. //#include <tr1/unordered_map>
  17. #define freopenr freopen("in.txt", "r", stdin)
  18. #define freopenw freopen("out.txt", "w", stdout)
  19. using namespace std;
  20. //using namespace std :: tr1;
  21.  
  22. typedef long long LL;
  23. typedef pair<int, int> P;
  24. const int INF = 0x3f3f3f3f;
  25. const double inf = 0x3f3f3f3f3f3f;
  26. const LL LNF = 0x3f3f3f3f3f3f;
  27. const double PI = acos(-1.0);
  28. const double eps = 1e-8;
  29. const int maxn = 2e3 + 5;
  30. const LL mod = 1e9 + 7;
  31. const int N = 1e6 + 5;
  32. const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
  33. const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
  34. const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
  35. inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
  36. inline int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); }
  37. int n, m;
  38. const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  39. const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  40. inline int Min(int a, int b){ return a < b ? a : b; }
  41. inline int Max(int a, int b){ return a > b ? a : b; }
  42. inline LL Min(LL a, LL b){ return a < b ? a : b; }
  43. inline LL Max(LL a, LL b){ return a > b ? a : b; }
  44. inline bool is_in(int r, int c){
  45. return r >= 0 && r < n && c >= 0 && c < m;
  46. }
  47.  
  48. int a[maxn], b[maxn];
  49.  
  50. int main(){
  51. while(scanf("%d %d", &n, &m) == 2){
  52. memset(b, 0, sizeof b);
  53. for(int i = 1; i <= n; ++i){
  54. scanf("%d", a+i);
  55. if(a[i] <= m) ++b[a[i]];
  56. }
  57.  
  58. int ans1 = n / m;
  59. int ans2 = 0;
  60.  
  61. int cnt = 1;
  62. for(int i = 1; i <= n; ++i) if(a[i] <= m && b[a[i]] > ans1){
  63. --b[a[i]];
  64. for(int j = cnt; j <= m; ++j){
  65. if(b[j] < ans1) { ++b[j]; cnt = j; a[i] = j; ++ans2; break; }
  66. }
  67. }else if(a[i] > m){
  68. for(int j = cnt; j <= m; ++j){
  69. if(b[j] < ans1) { ++b[j]; cnt = j; a[i] = j; ++ans2; break; }
  70. }
  71. }
  72.  
  73. printf("%d %d\n", ans1, ans2);
  74. for(int i = 1; i <= n; ++i)
  75. if(i == 1) printf("%d", a[i]);
  76. else printf(" %d", a[i]);
  77. printf("\n");
  78. }
  79. return 0;
  80. }

CodeForces 723C Polycarp at the Radio (题意题+暴力)的更多相关文章

  1. Codeforces 723C. Polycarp at the Radio 模拟

    C. Polycarp at the Radio time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...

  2. codeforces 723C : Polycarp at the Radio

    Description Polycarp is a music editor at the radio station. He received a playlist for tomorrow, th ...

  3. 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 ...

  4. Codeforces 659F Polycarp and Hay 并查集

    链接 Codeforces 659F Polycarp and Hay 题意 一个矩阵,减小一些数字的大小使得构成一个连通块的和恰好等于k,要求连通块中至少保持一个不变 思路 将数值从小到大排序,按顺 ...

  5. Codeforces Round #310 (Div. 2)--A(简单题)

    http://codeforces.com/problemset/problem/556/A 题意:给一个01字符串,把所有相邻的0和1去掉,问还剩下几个0和1. 题解:统计所有的0有多少个,1有多少 ...

  6. CodeForces - 669D Little Artem and Dance 想法题 多余操作

    http://codeforces.com/problemset/problem/669/D 题意:n个数1~N围成一个圈.q个操作包括操作1:输入x, 所有数右移x.操作2:1,2位置上的数(swa ...

  7. Codeforces 659F Polycarp and Hay【BFS】

    有毒,自从上次选拔赛(哭哭)一个垃圾bfs写错之后,每次写bfs都要WA几发...好吧,其实也就这一次... 小白说的对,还是代码能力不足... 非常不足... 题目链接: http://codefo ...

  8. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  9. CodeForces 1005D Polycarp and Div 3(思维、贪心、dp)

    http://codeforces.com/problemset/problem/1005/D  题意: 给一个仅包含数字的字符串,将字符串分割成多个片段(无前导0),求这些片段里最多有多少是3的倍数 ...

随机推荐

  1. RQNOJ273 马棚问题

    题目描述 每天,小明和他的马外出,然后他们一边跑一边玩耍.当他们结束的时候,必须带所有的马返回马棚,小明有K个马棚.他把他的马排成一排然后跟随它走向马棚,因为他们非常疲劳,小明不想让他的马做过多的移动 ...

  2. 远程连接mongodb时,27017端口连接不上的解决办法

    一.背景描述: 我在linux  RED7上安装了mongodb,并没有修改mongodb的配置文件.然后通过另外一台电脑用pymongo连接mongodb时,报错:timeout. ping IP ...

  3. Solr Admin管理界面使用说明

    Notice:本说明基于Solr6.4.2. 本文讨论的是如何使用Solr Admin UI. 一级菜单 图1.SolrCloud模式 图2.单机Solr模式 Logging:展示Solr的日志,不用 ...

  4. 深入理解计算机操作系统——第11章:CS模型,网络

    网络编程: 11.1 客户端-服务器编程模型 (1)一个应用是由一个服务器进程和一个或多个客户端进程组成. (2)服务器管理某种资源,并且操纵这种资源来为客户端服务. CS模型: CS的基本操作是事务 ...

  5. C. Day at the Beach---cf559

    http://codeforces.com/problemset/problem/599/C 题目大意: 有n个城堡的高度   让你最多分成几个块   每个块排过序之后 整体是按照升序来的 分析:   ...

  6. Atom编辑Markdown文件保存后行尾的空格自动消失的问题解决

    Markdown文件的行尾增加两个空格表示一行结束需要换行. 但保存文件后,行尾的空格自动消失,导致不换行. 解决方法: 1.[Edit]->[Preferences]->[Package ...

  7. c++之NVI手法

    non-virtual interface(NVI)手法:令用户通过public non-virtual成员函数间接调用private virtual函数,将这个non-virtual函数称为virt ...

  8. 【转】海量数据处理算法-Bloom Filter

    1. Bloom-Filter算法简介 Bloom Filter(BF)是一种空间效率很高的随机数据结构,它利用位数组很简洁地表示一个集合,并能判断一个元素是否属于这个集合.它是一个判断元素是否存在于 ...

  9. 《javascript设计模式》读书笔记二(封装和隐藏信息)

    1.为什么要封装和信息隐藏 做过编程的朋友们知道"耦合"这个词.事实上封装的效果就是为了解耦,让类和类之间没有太多的联系,防止某一天改动某一类的时候,产生"多米骨诺牌效应 ...

  10. 说说Android应用的persistent属性(转)

    1 启动persistent应用 在Android系统中,有一种永久性应用.它们对应的AndroidManifest.xml文件里,会将persistent属性设为true,比如: <appli ...