Insets to visit a nearby village, coincidentally, the village streets lined with K shape perfect binary tree layer is very similar to that of K by K perfect binary tree layer 2 K? 12 ^ K - 12 K? 1 nodes, each node contains a marked apartment buildings, moreover, in addition to the last layer of the building, all of the buildings have a left and right child nodes (as shown in the figure below), layer 2 and layer 3 perfect binary tree
Visited a village in the picture all the buildings, and write down the exact order entry, now he wants to give you a description of the appearance of the village, but he can't remember, fortunately, he remembered the way he visit these buildings:
At first, he stood before the only a building of the first layer,
If he is now faced with building a he hasn't visited left child node, he will go to the front of the left child node,
If the building doesn't left child node, or he has already visited the left child node, he will enter the building, on a piece of paper to write down the building of the house number,
If he has already visited the building currently, and the building there is a right child node, he will go to the front of the right child nodes of the
If he visited the current around the building and its child nodes, he will return to the current construction of the parent node, after visited the village in the picture above, a piece of paper to write the Numbers: wrote above the first village in the 2-1-3 s, wrote above the second village in the 1-6-4-1-6-4-7, your task is to write a program to help rebuild picture each layer building house number,
Input format
The first line of input contains an integer K, namely insets on a visit to the village on the number of layers, the second line of the input contains 2 K? 12 ^ K - 12 K? One integer, this is a small house number sequence, the drawings and the number of house number will be the only, in 1 to 2 k? 12 ^ K - 12 K? 1,
The output format
Output is composed of K line, the first line contains the first village I layer building house number,
Input and output sample
Enter the # 1
2
1 2 3
Output # 1
1
2, 3,
Enter the # 2
3
1 2 3 4 5 6 7
Output # 2
3
6 2
1, 4, 5, 7
So what's the problem with writing
# include & lt; Iostream>
# include & lt; Cmath>
using namespace std;
Num int a [1048586], [21] [1048586], k, n, abcde=0;
Bool visit [21].
Void tree (int the begin, int the end, int x)
{
Int the middle;
if(! Visit [x]) abcde=0;
Visit [x]=1;
Middle=(end - the begin + 2)/2 + the begin - 1;
Num [x] [abcde]=a (middle);
Abcde++;
If (x==k) return;
Tree (the begin, middle - 1, x + 1);
Tree (middle + 1, end, x + 1);
}
Int main ()
{
int i,j;
Cin> k;
N (2, k)=pow - 1;
For (I=1; i <=n; I++)
{
Cin> A, [I].
}
Tree (1, n, 1);
for(i=0; i
for(j=0; J & lt; Pow (2, I + 1); J++)
{
Cout
Cout
return 0;
}