这题题意不太好理解,但是可以通过样例推。主要考察思维的全面性,注意把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. python_py2和py3读写文本区别

    python2和python3的区别? python 2  str             对应      python3 bytes python 2 uincode            对应   ...

  2. VNC配置

    简介 VNC (Virtual Network Console)是虚拟网络控制台的缩写.它 是一款优秀的远程控制工具软件,由著名的 AT&T 的欧洲研究实验室开发的.VNC 是在基于 UNIX ...

  3. DVWA安装问题(phpStudy)

    安装过程出现的问题: 1.PHP function allow_url_include disabled 注意DVWA的版本    PHP version: 5.4.45 打开/phpStudy/ph ...

  4. javascipt中的DOM对象

    1.HTML中DOM对象的概念 HTML Document Object Model(文档对象模型) HTML DOM定义了访问和操作HTML文档的标准方法 HTML DOM把HTML文档呈现为带有元 ...

  5. OS模块的常用内置方法

    chdir 修改当前工作目录到指定目录 Change the current working directory to the specified path. chmod 修改一个文件的访问权限 Ch ...

  6. iOS-获取通讯录联系人信息

    头文件 #import <AddressBook/AddressBook.h> #import <AddressBookUI/AddressBookUI.h> 授权 关于通讯录 ...

  7. ffmpeg转码使用硬件加速

    需求源于手机拍摄的视频,默认参数码率较大,拍摄的文件体积较大,不便于保存和转发.手机默认拍照的720P视频,默认码率达到4M,实际上转成1M就差不多了.FFmpeg默认的转码是使用软件解码,然后软件编 ...

  8. HEOI2016 题解

    HEOI2016 题解 Q:为什么要在sdoi前做去年的heoi题 A:我省选药丸 http://cogs.pro/cogs/problem/index.php?key=heoi2016 D1T1 树 ...

  9. CF 741D. Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths [dsu on tree 类似点分治]

    D. Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths CF741D 题意: 一棵有根树,边上有字母a~v,求每个子树中最长的边,满 ...

  10. POJ 1704 Georgia and Bob [阶梯Nim]

    题意: 每次可以向左移动一个棋子任意步,不能跨过棋子 很巧妙的转化,把棋子间的空隙看成石子堆 然后裸阶梯Nim #include <iostream> #include <cstdi ...