这题题意不太好理解,但是可以通过样例推。主要考察思维的全面性,注意把b[m]特殊处理下。

AC代码:

#include<cstdio>
#include<cstring>
const int maxn=2000+5;
int cnt[maxn],play[maxn];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    memset(cnt,0,sizeof(cnt));
    for(int i=1;i<=n;++i){
        scanf("%d",&play[i]);
        if(play[i]<=m) {
            cnt[play[i]]++;
        }
    }
    //确定goal
    int goal=n/m;
    int change=0;
    if(cnt[m]>goal){ //处理m
        for(int i=1;i<=n&&cnt[m]>goal;++i){
            if(play[i]==m){
                for(int j=1;j<m;++j){
                    if(cnt[j]<goal) {
                        change++;
                        cnt[m]--;
                        cnt[j]++;
                        play[i]=j;
                        break;
                    }
                }
            }

        }
    }
    for(int i=1;i<=m;++i){
        if(cnt[i]<goal){
            for(int j=1;j<=n&&cnt[i]<goal;++j){
                int u=play[j];
                if(u>m||cnt[u]>goal){
                    change++;
                    cnt[i]++;
                    if(u<=m) cnt[u]--;
                    play[j]=i;
                }
            }
        }
    }
    printf("%d %d\n",goal,change);
    for(int i=1;i<=n;++i){
        if(i==1) printf("%d",play[i]);
        else printf(" %d",play[i]);
    }
    printf("\n");

    return 0;
}

如有不当之处欢迎指出!!

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

  3. cf723c Polycarp at the Radio

    Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be re ...

  4. codeforces 723C : Polycarp at the Radio

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

  5. 【23.48%】【codeforces 723C】Polycarp at the Radio

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【Codeforces 723C】Polycarp at the Radio 贪心

    n个数,用最少的次数来改变数字,使得1到m出现的次数的最小值最大.输出最小值和改变次数以及改变后的数组. 最小值最大一定是n/m,然后把可以改变的位置上的数变为需要的数. http://codefor ...

  7. codeforces723----C. Polycarp at the Radio

    //AC代码...表示很晕 #include <iostream> using namespace std; ],b[]; int main() { int n,m,cnt; cin &g ...

  8. 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个人演唱歌曲 ...

  9. CodeForces 723C Polycarp at the Radio (题意题+暴力)

    题意:给定 n 个数,让把某一些变成 1-m之间的数,要改变最少,使得1-m中每个数中出现次数最少的尽量大. 析:这个题差不多读了一个小时吧,实在看不懂什么意思,其实并不难,直接暴力就好,n m不大. ...

随机推荐

  1. linux指令--ls

    本篇博客转自http://www.cnblogs.com/peida/archive/2012/10/23/2734829.html,在原作者基础上做了修改和总结. ls命令是linux下最常用的命令 ...

  2. alwaysOn中关于维护计划的应用方案

    由于alwaysOn环境下主副本所在的实际服务器不固定, 所以我目前采取的方案是创建维护计划的时候, 在各个服务器上创建一份维护计划. (假设有2个服务器需要故障转移, 那么就在这两个服务器上分别创建 ...

  3. 【高并发简单解决方案】redis队列缓存 + mysql 批量入库 + php离线整合

    需求背景:有个调用统计日志存储和统计需求,要求存储到mysql中:存储数据高峰能达到日均千万,瓶颈在于直接入库并发太高,可能会把mysql干垮. 问题分析 思考:应用网站架构的衍化过程中,应用最新的框 ...

  4. 面向对象_04【关键字:super使用】

    super关键字:解决当子类重写父类对象方法后,子类对象无法访问父类的成员1,调用父类成员变量和方法 super.成员变量 super.成员方法([参数1,参数2.......])Example: / ...

  5. 通过url获取相应的location信息

    var properties = ['href', 'origin', 'host', 'hostname', 'port', 'pathname', 'search', 'hash']; var g ...

  6. 忽略node.js服务中favicon.icon的请求

    场景 一个最简单的node.js的http服务 const http = require('http'); const server = http.createServer(function(req, ...

  7. 异常检测算法:Isolation Forest

    iForest (Isolation Forest)是由Liu et al. [1] 提出来的基于二叉树的ensemble异常检测算法,具有效果好.训练快(线性复杂度)等特点. 1. 前言 iFore ...

  8. ServiceStack.OrmLite T4模板使用记录

    前言 最近研究了下ServiceStack.OrmLite,文档中也提到了使用T4模板对数据库中已经有了表进行实体的映射,这里也顺便记录下使用的步骤和情况. 开始使用 引用T4模板 首先我们创建一个工 ...

  9. css模板

    最近好多人问我博客的css模板.... 现在是高三,没多少时间,趁放假赶紧更一下 主体就是把博客园的一个模板改动了一点 上面的图片特效,也是从别人那里得到的代码,大致就是下面那些,下面的三个图片换成自 ...

  10. BZOJ 1937: [Shoi2004]Mst 最小生成树 [二分图最大权匹配]

    传送门 题意: 给一张无向图和一棵生成树,改变一些边的权值使生成树为最小生成树,代价为改变权值和的绝对值,求最小代价 线性规划的形式: $Min\quad \sum\limits_{i=1}^{m} ...