codeforces37C

CF37C Old Berland Language

 

 sol:直接暴力模拟下去,长度加了就补0,凑个数就+1,凑不好就puts(“no”)

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
    ll s=0; bool f=0; char ch=' ';
    while(!isdigit(ch))    {f|=(ch=='-'); ch=getchar();}
    while(isdigit(ch)) {s=(s<<3)+(s<<1)+(ch^48); ch=getchar();}
    return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
    if(x<0) {putchar('-'); x=-x;}
    if(x<10) {putchar(x+'0'); return;}
    write(x/10); putchar((x%10)+'0');
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=1005;
int n,nn,a[N],b[N],c[N];
vector<string>ans;
#define PB push_back
bool used[N];
inline bool add(string &s)
{
    int i;
    s[s.size()-1]++;
    for(i=s.size()-1;i>0;i--) if(s[i]=='2') {s[i]='0'; s[i-1]++;}
    return (s[0]=='2')?0:1;
}
int main()
{
    freopen("codeforces37C_data.in","r",stdin);
    int i,j;
    string s;
    R(n);
    for(i=1;i<=n;i++)
    {
        a[i]=b[i]=read(); c[a[i]]++;
    }
    sort(a+1,a+n+1); nn=unique(a+1,a+n+1)-a-1;
    a[0]=0;
//    cout<<"nn="<<nn<<endl;
    for(i=1;i<=nn;i++)
    {
        for(j=a[i-1]+1;j<=a[i];j++) s+='0';
        bool flg=0,oo;
        for(;;)
        {
//            cout<<"c="<<c[a[i]]<<endl;
            if(!c[a[i]]) break;
            if(flg)
            {
                oo=add(s);
                if(!oo) return puts("NO"),0;
            }
            flg=1; c[a[i]]--; ans.PB(s);
        }
        oo=add(s); if((!oo)&&(i!=nn)) return puts("NO"),0;
    }
//    cout<<"ans.size()="<<ans.size()<<endl;
    puts("YES");
    for(i=1;i<=n;i++)
    {
        for(j=0;j<ans.size();j++) if(ans[j].size()==b[i]&&(!used[j]))
        {
            cout<<ans[j]<<endl; used[j]=1; break;
        }
    }
    return 0;
}
View Code

 

posted @ 2019-08-08 20:10  yccdu  阅读(188)  评论(2编辑  收藏  举报