Describe
Small hi and small ho cracked a problem, and finally came to the last level. Just open the treasure chest before you can clear the game.
The chest was locked by a strange institution:
This institution is a ring with a total of 2^n areas, each of which can change color and switch between black and white colors.
Small Ho control protagonist in the surrounding explored a bit, sure enough to find a piece of paper:
The black part of the organ is represented as 1, the white part is represented as 0, and the counterclockwise continuous N-field represents a binary number. The condition of opening the institution is to adjust the distribution of the black and white color of the ring rationally, so that the organ can represent 0~2^n-1 all the numbers. I tried many times, after all, there is no way to open, have to write down the law of the organs to crack. --by unknown adventurer.
Little ho: What does that mean?
Little hi: I'll give you an example, if n=3, we can turn it clockwise, so that the 3 areas just below are represented as:
Because Black is represented as 1, White is represented as 0. Then the above three states correspond to the binary (001), (010), (101)
A new number can be obtained for each area of rotation. You can turn 2^n times, that is, 2^n numbers. We're going to adjust the position of the black and white area so that this 2^n number happens to be 0~2^n-1
Little ho: I understand. If n=2, the black and white color block on the ring is adjusted to "black black White", corresponding to "1100". Is "11", "10", "00", "01" Four numbers, just 0~3. So this "black and white" can open the agency?
Little hi: I think so.
Little ho: It doesn't look very hard, I'll try!
Input
Line 1th: 1 positive integers, N. 1≤n≤15
Output
Line 1th: A 01-string length of 2^n, indicating a distribution scheme that meets the requirements
Sample input
3
Sample output
00010111
- To this 2^n a point to build a map, if a->b to build the edge, to meet the first B-deletion is equal to B to delete the last one, a>>1 = = B & 2^ (n-1)-1, but in this case, is to require a program to make each point pass ——— > Hamiltonian circuit, The Hamiltonian circuit is NP problem, and it is troublesome to realize it.
- In another way, we'll find a way to convert Hamilton to Euler. Then use the last one to solve the problem. We turn the dots into edges.
- Output, note that the first bit is the output of all, the output of the last one, and the end of the road back to not output.
#include <cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<cmath>using namespacestd;intused[100010],path[100010],n,m,cnt,tot=1;intlaxt[100010],next[100010],to[100010];voidPrint_two (intN) {if(n) F (n>>1); Else return; printf ("%d", n%2); } voidAddintUintv) {next[++tot]=Laxt[u]; Laxt[u]=tot; To[tot]=v;}voidDfsintu) { for(intI=laxt[u];i;i=Next[i]) { if(!Used[i]) {Used[i]=1; DFS (To[i]); }} path[++cnt]=u;}intMain () {inti,u,v,p; scanf ("%d",&N); N=pow (2, N); for(i=0; i<n;i++) {Add (i>>1,i& ((n>>1)-1)); } DFS (1); Print_two (path[1]); for(i=2; i<cnt;i++) printf ("%d",path[i]&1); return 0;}
HihoCoder1182 Oralu (Fleury algorithm)