这题题意不太好理解,但是可以通过样例推。主要考察思维的全面性,注意把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. Log4j源码解析--Layout类解析

    本文转载上善若水的博客,原文出处:http://www.blogjava.net/DLevin/archive/2012/07/04/382131.html.感谢作者的分享. Layout负责将Log ...

  2. Java中Unsafe类详解

    http://www.cnblogs.com/mickole/articles/3757278.html Java不能直接访问操作系统底层,而是通过本地方法来访问.Unsafe类提供了硬件级别的原子操 ...

  3. 转-Web Service中三种发送接受协议SOAP、http get、http post

    原文链接:web服务中三种发送接受协议SOAP/HTTP GET/HTTP POST 一.web服务中三种发送接受协议SOAP/HTTP GET/HTTP POST 在web服务中,有三种可供选择的发 ...

  4. CentOS 7 修改SSH端口号 和 ssh无法使用密码登录 和 查看pid 端口占用

    如下示例把SSH默认端口22改为122. 1 修改/etc/ssh/sshd_config文件 #Port #找到改行,如果还想继续使用该端口,可以把#去掉,如果使用新端口,可以默认不管 Port # ...

  5. Servlet--HttpUtils类

    定义 public class HttpUtils 收集 HTTP Servlet 使用的静态的有效的方法. 方法 1.getRequestURL public static StringBuffer ...

  6. Android 使用EventBus发送消息接收消息

    基本使用 自定义一个类 public class LoginEvent { private String code;//是否成功 public LoginEvent(String code) { th ...

  7. 达尔稳usb转RJ45的接口转换器(usb2.0接口)在ubuntu16.04中驱动(r8152)编译安装与使用

    淘宝买了usb转RJ45的接口转换器:https://detail.tmall.com/item.htm?id=524808012954&ali_refid=a3_430582_1006:11 ...

  8. print,printf,println

    1.print,打印你要打印的东西. 2.printf,可以定义要打印数据的格式,弄个%d,%f之类的.而print不行. 3.println, 会在打印完内容后换行. println和print的差 ...

  9. XBIM 基于 WexBIM 文件在 WebGL 浏览和加载

    目录 xBIM 应用与学习 (一) xBIM 应用与学习 (二) xBIM 基本的模型操作 xBIM 日志操作 XBIM 3D 墙壁案例 xBIM 格式之间转换 xBIM 使用Linq 来优化查询 x ...

  10. Kitty猫基因编码

    原题链接:https://www.luogu.org/problemnew/show/2562#sub 简单的递归题.记录一下前缀和然后二分求解就好. 参考代码: #include <iostr ...