Codeforces_723_C

Posted 冷暖知不知

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces_723_C相关的知识,希望对你有一定的参考价值。

http://codeforces.com/problemset/problem/723/C

 

将n个数替换为1-m内的数,使得1-m的个数的最小值最大,并且替换步骤最少。注意,不必将每个数都替换!!

 

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define INF 0x3f3f3f3f
using namespace std;

int a[2005],b[2005] = {0};

int main()
{
    int m,n;
    scanf("%d%d",&n,&m);
    for(int i = 1;i <= n;i++)
    {        
        scanf("%d",&a[i]);    
        if(a[i] <= m)    b[a[i]]++;
    }
    int ans = n/m;
    int cnt = 0;    
    for(int i = 1;i <= n;i++)
    {
        if(a[i] > m || a[i] <= m && b[a[i]] > ans)
        {
            int j;
            for(j = 1;j <= m;j++)
            {
                if(b[j] < ans)    break;
            }
            if(j == m+1)    break;
            if(a[i] <= m)    b[a[i]]--;
            a[i] = j;
            b[j]++;
            num++;
        }
    }    
    printf("%d %d\n",ans,num);
    int flag = 1;
    for(int i = 1;i <= n;i++)
    {
        if(flag)
        {
            printf("%d",a[i]);
            flag = 0;
        }
        else
        {
            printf(" %d",a[i]);
        }
    }
    printf("\n");
    return 0;
}
    

 

以上是关于Codeforces_723_C的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces_723_D

Codeforces_723_A

Codeforces_723_B

Codeforces Round #723 (Div. 2) (A~C题题解)

Codeforces Round #723 (Div. 2) A. Mean Inequality(构造)

codeforces723----C. Polycarp at the Radio