"Recover" the String codeforces 708B

Source: Internet
Author: User

The question is not very detailed, some theorems are not proved directly to give, need the reader to think, if you do not understand welcome to ask questions in the discussion area

The number of 0 and 1 can be determined by the number of 00 and 11
Assuming that the number of 00 is B, A * (A-1)/2=b must be met, and a is an integer
At this point, a is the number of 0, the number of 1 is the same
At the same time, 01 and 10 of the number and must be 0 of the number of * *
Then construct a 00000000001111111111 such a string, which is not present in 10 such subsequence
We call the rightmost lump 1 called "No exchange of 1", and then each time you choose the leftmost one 1 and x (x to be determined) a 0 exchange
Note that after the exchange with the X 0, the number of 10 generated is the number 1 crosses 0
Is that really the case?
For such a string 0000011111, we assume that the first step is the first 1 and the second 0 interchange, which spans 4 0
becomes 0100001111, when we perform the second step
Found "No exchange of 1", the leftmost 1 and the first 2,3,4,5 0 exchange time, satisfies the above law
But in exchange with the first 0, it is not satisfied, because it crosses a 1
So we want to let the exchange does not cross 1, that is satisfied, each exchange to the first x 0, this x is a non-descending
So each exchange as far as possible and the left 0 exchange, and the cumulative amount of 10 generated, according to the above analysis, it is easy to determine exactly and the first few 0 exchange
The question becomes, "query the position of x 0."
Balance Tree


The above is my intellectual disability practice, and then zrf the great God taught me to behave:
The premise is to meet the number of 00,11,10,01 limit, that is the Basic Law discussed above
Put 0 or 1 from left to right, save how many 0 are not put
If there are x 0 not put, then we put a 1, resulting in the number of 10 is X
Try to put 1 in front of the number of no more than 10, greedy
Linear


Wait a minute! It's not finished! After I wa a few times, I found to special handling A00 = = 0 and A11 = = 0 case
Notice that A00 = = 0, the final answer can have a 0, or not 0
Is there 0 depending on the number of A10 and A01?
That is, when a10 = = 0 && A01 = = 0 && A00 = = 0, no 0
When a10! = 0 && A01! = 0 && A00 = = 0, there is a 0
The same is true for the number 1, so talk about it.


Why am I so mentally retarded? I'm trapped in the data range.
According to the data range, the number has a maximum of 90,000, so I would like O (Nlogn)
The linear procedure began to think, and later felt that DIV1B could not be so naive ... Just abandoned it.

The following code, no comments, but should compare understood it ... I don't understand. Welcome to the discussion area questions

1#include <iostream>2#include <cstring>3#include <algorithm>4#include <cmath>5#include <cstdio>6#include <cstdlib>7 8 using namespacestd;9 Ten intA00, A01, A10, A11; One inta0, A1, N; A  - voidquit () { -cout <<"Impossible"<< Endl; Exit0); the } -  - intMain () { -CIN >> A00 >> A01 >> A10 >>A11; +a0 = sqrt (a00<<1)+1; A1 = sqrt (a11<<1)+1; -     if(A01+a10+a11 = =0) A1 =0; +     if(A01+a10+a00 = =0) a0 =0; A     if(A0* (a0-1)/2! = A00 | | A1* (a1-1)/2!=A11) quit (); at     if(A01+a10! = a0*A1) quit (); -n = a0+A1; -      for(inti =0; I < n; ++i) { -         if(A10 >= a0) cout <<1, A10-=A0; -         Elsecout <<0, --A0; -     } in     if(!n) cout <<0; -     return 0; to}

"Recover" the String codeforces 708B

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.