首页 > 代码库 > CodeForces 723C Polycarp at the Radio

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