这题题意不太好理解,但是可以通过样例推。主要考察思维的全面性,注意把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. chroot: failed to run command `/bin/bash': No such file or directory

    1 使用chroot命令时报错如下: testupgrade:/ # chroot /sb chroot: cannot change root directory to /sb: No such f ...

  2. SQL Server中的变更捕获技术--简单部署

    ------准备------ CREATE DATABASE db_test_cdc ,) ,name )); INSERT INTO t1(name)VALUES('test') ------开始- ...

  3. 并发思考-actor和thread那个好点?

    实验课题:测试actor和thread那个好? 实验方法:利用数据库连接池创建连接,交由线程去工作,在回收,看看程序运行状况. 实验步骤: 1.创建数据连接工具类: import java.sql.{ ...

  4. Android组件化框架设计与实践

    在目前移动互联网时代,每个 APP 就是流量入口,与过去 PC Web 浏览器时代不同的是,APP 的体验与迭代速度影响着用户的粘性,这同时也对从事移动开发人员提出更高要求,进而移动端框架也层出不穷. ...

  5. spring重要类说明

  6. Python函数可变参数*args及**kwargs详解

    初学Python的同学们看到代码中类似func(*args, **kwargs)这样的函数参数定义时,经常感到一头雾水. 下面通过一个简单的例子来详细解释下Python函数可变参数*args及**kw ...

  7. React 16.3来了:带着全新的Context API

    文章概览 React在版本16.3-alpha里引入了新的Context API,社区一片期待之声.我们先通过简单的例子,看下新的Context API长啥样,然后再简单探讨下新的API的意义. 文中 ...

  8. 数据库MySQL的基本操作

    1.MySQL数据库的安装: CentOS6上mysql服务端和客户端的安装和启动: #使用yum安装mysql数据库的服务端和客户端 yum install -y mysql mysql-serve ...

  9. RHEL7.2安装

    先在系统启动的时候按下Del键(有些系统是F2键)进入BIOS,设置从光盘启动. 系统只有2个USB口时,1个要接光驱,另外1个口不能同时接键盘和鼠标,可以接1个USB集线器,键盘和鼠标同时接入到集线 ...

  10. Spring整合JMS(一)-基础篇

    1.基础知识 图1   同步通信和异步通信通信过程示意图 RMI使用的是同步通信,JMS使用的是异步通信.从图1可以看出异步通信的好处就是减少了不必要的等待,提高了效率. JMS中有两个主要的概念:消 ...