CodeForces 723C Polycarp at the Radio

Posted

tags:

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

构造。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-10;
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
    char c = getchar();
    x = 0;
    while(!isdigit(c)) c = getchar();
    while(isdigit(c))
    {
        x = x * 10 + c - 0;
        c = getchar();
    }
}

int a[2010],n,m,sum;
int b[2010];
int c[2010];
int ans1,ans2;

struct X
{
    int id,num;
}s[2100];

bool cmp(X a,X b)
{
    return a.num>b.num;
}

int main()
{
    cin>>n>>m;

    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++)
        if(a[i]>=1&&a[i]<=m) sum++;

    ans1=n/m;

    if(sum==0)
    {
        printf("%d %d\n",ans1,n);
        for(int i=1;i<=n-(m-1)*ans1;i++) printf("1 ");
        for(int i=2;i<=m;i++)
        {
            for(int j=1;j<=ans1;j++) printf("%d ",i);
        }
        printf("\n"); return 0;
    }

    for(int i=1;i<=m;i++) c[i]=ans1;

    for(int i=1;i<=n;i++)
    {
        if(a[i]>=1&&a[i]<=m&&c[a[i]]!=0)
        {
            b[i]=a[i];
            c[a[i]]--;
        }
    }

    for(int i=1;i<=n;i++)
    {
        if(b[i]!=0) continue;

        for(int j=1;j<=m;j++)
        {
            if(c[j]==0) continue;
            b[i]=j;
            c[j]--;
            ans2++;
            break;
        }
    }

    for(int i=1;i<=n;i++)
    {
        if(b[i]!=0) continue;
        b[i]=a[i];
    }

    printf("%d %d\n",ans1,ans2);
    for(int i=1;i<=n;i++) printf("%d ",b[i]);
    printf("\n");

    return 0;
}

 

以上是关于CodeForces 723C Polycarp at the Radio的主要内容,如果未能解决你的问题,请参考以下文章

cf723c Polycarp at the Radio

Codeforces 723c [贪心][乱搞]

codeforces - 723C 题解

CodeForces - 1003A Polycarp‘s Pockets

Codeforces 861D - Polycarp's phone book

CodeForces 659F Polycarp and Hay