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;
}
    

 

posted @ 2016-10-03 23:48  zzzzzzzzhu  阅读(192)  评论(0编辑  收藏  举报