Codeforces 37C (Miscellaneous questions)

Source: Internet
Author: User

Test instructions: Given the length of n 01 strings, any one 01 string cannot be the prefix of another string, which requires the output of these strings.

Start very confused, the main feeling is difficult to output, to determine whether there is a solution or very easy. Look at the official work, because the number of strings must be, you can put all the strings can be added to the queue, if the number is enough to stop joining. Then it is output in turn, did not pay attention to the order WA once,,, and then the code changed so ugly.

#include <iostream>#include<map>#include<algorithm>#include<cstdio>#include<cstring>#include<cstdlib>#include<vector>#include<queue>#include<stack>#definePB Push_backusing namespaceStd;typedefLong Longll;Const intmaxv=1005;intN;intA[maxv],b[maxv];queue<string>Q;vector<string>Ans;stack<string> xxx[1005];intMain () {CIN>>N;  for(intI=0; i<n;i++) {scanf ("%d",&A[i]); B[i]=A[i]; } sort (A,a+N); intk=0; Q.push (string("")); inti;  for(i=0; i<n;i++){         while(!Q.empty ()) {             while(Q.front (). Size () <a[i]-1){                stringtt=Q.front ();                Q.pop (); if(Q.size () <N) {Q.push (TT+'0'); Q.push (TT+'1'); }            }            stringnow=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(intI=0; i<n;i++) {cout<<xxx[b[i]].top () <<Endl;        Xxx[b[i]].pop (); }    }    return 0;}
View Code

Codeforces 37C (Miscellaneous questions)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.