• CodeForces 37C(杂题


    题意:给出N个01串的长度,任意一个01串不能是另一个串的前缀,要求输出这些串。

    开始很迷茫,主要是感觉很难输出,要判定是否有解还是挺容易的。看了下官方题解,由于串的数目一定,可以把所有能用的串都加到队列里,如果数目足够就停止加入。然后就是依次输出,没注意顺序WA了一次,,,,然后代码改得好丑。。

    #include<iostream>
    #include<map>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<vector>
    #include<queue>
    #include<stack>
    #define pb push_back
    using namespace std;
    typedef long long ll;
    const int maxv=1005;
    int N;
    int a[maxv],b[maxv];
    queue<string> Q;
    vector<string> ans;
    stack<string> xxx[1005];
    int main(){
        cin>>N;
        for(int i=0;i<N;i++){
            scanf("%d",&a[i]);
            b[i]=a[i];
        }
        sort(a,a+N);
        int k=0;
        Q.push(string(""));
        int i;
        for(i=0;i<N;i++){
            while(!Q.empty()){
                while(Q.front().size()<a[i]-1){
                    string tt=Q.front();Q.pop();
                    if(Q.size()<N){
                        Q.push(tt+'0');
                        Q.push(tt+'1');
                    }
                }
                string now=Q.front();
                Q.pop();
                if(now.size()<a[i]-1||now.size()>a[i]) continue;
                if(now.size()==a[i]-1){
                    ans.pb(now+'1');
                    xxx[a[i]].push(now+'1');
                    Q.push(now+'0');
                    break;
                }else if(now.size()==a[i]){
                    ans.pb(now);
                    xxx[a[i]].push(now);
                    break;
                }
            }
            if(Q.empty()) break;
        }
        if(ans.size()!=N) puts("NO");
        else{
            puts("YES");
            for(int i=0;i<N;i++){
                cout<<xxx[b[i]].top()<<endl;
                xxx[b[i]].pop();
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    关于网络字节序(network byte order)和主机字节序(host byte order)
    关于垃圾回收,我来解释下为什么LocalConnection可以实现垃圾回收
    解决Form中ExternalInterface的Bug问题
    AS3里var aa:String是null还是""?
    IE并发连接限制(as)
    tar
    mysql默认端口号3306
    flex经验
    这个游戏不错
    nginx介绍
  • 原文地址:https://www.cnblogs.com/Cw-trip/p/4567895.html
Copyright © 2020-2023  润新知