这题题意不太好理解,但是可以通过样例推。主要考察思维的全面性,注意把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. Windows核心编程&进程

    1. 进程的定义 说白了进程就是一个正在运行的执行程序,包含内核对象和独立的地址空间,内核对象负责统计和管理进程信息,地址空间包括所有可执行文件或DLL 模块的代码和数据.动态内存分配(线程堆和栈的分 ...

  2. Storm保证消息处理

    Guaranteeing Message Processing Storm保证每一个tuple被完全处理.Strom中一个核心的机制是它提供了一种跟踪tuple血统的能力,它使用了一种十分有效的方式跟 ...

  3. 用SecureCRT来上传和下载文件

    用SSH管理linux服务器时经常需要远程与本地之间交互文件.而直接用SecureCRT自带的上传下载功能无疑是最方便的,SecureCRT下的文件传输协议有ASCII.Xmodem.Zmodem. ...

  4. 流API--原始类型流

    到目前为止,我们已经将整型收集到了一个Stream<Integer>的流中,不过将每个整数包装成相应对象显然是一个低效的做法,对于其他的基本类型也是一样,我们前面说过jdk提供包装类已经自 ...

  5. CSS常用字体名称

    CSS样式中常用的字体名称   css中引入字体: @font-face { font-family: "AncientWar"; src: url('style/css/font ...

  6. shell第三篇

    第三篇本文摘自鸟哥的私房菜:http://cn.linux.vbird.org/linux_basic/0105computers.php#program(当年看的时候浮光掠影,现在回头发现,经典就是 ...

  7. C# 类型基础(上)

    C#类型都派生自System.Object 祖先的优良传统:Object的公共方法 Equals: 对象的同一性而非相等性 GetHashCode:返回对象的值的哈希码 ToString:默认返回类型 ...

  8. Git多帐号配置,管理多个SSH

    查看自己所有的SSH-Key $ cd ~/.ssh $ ls id_rsa id_rsa.pub known_hosts 如果你已经创建过git账号那你可能和我一样会看到只有一个SSH-Key, 这 ...

  9. spring之AspectJ基于注解 AOP编程

    一.前言 使用注解代替之前在spring配置文件中配置目标类.切面类和aop配置. 二.注意 需要注意的是,需要在spring配置文件中引入如下,如果不添加,切面类中的@Aspect注解将不起作用 & ...

  10. iOS-Wonderful 完美颜色库

    开发中颜色的使用也是非常频繁的,这里推荐一个dsxNiubility大牛写的颜色库:Wonderful:它的好用就是很清楚的把每个常用的颜色进行了由浅到深的分层,让我们使用时可以根据自己对颜色的深浅直 ...