NOIP 2004 universal group rematch FBI Tree

Source: Internet
Author: User
Tags printf

NOIP 2004 universal group rematch FBI Tree

1. Read the topic, but also some unintelligible.

2. Manual simulation of the sample to understand the test instructions.

10001011

The FBI tree is shown in the figure below

F

F F

F B F I

I b b b I b i I

1) the root node of T is R, whose type is the same as the type of string s, and this sentence is the core of the core, that is, the F B I three kinds of root nodes.

3. The next programming implementation is the focus. First, the children believe that a layer of achievement, with a one-dimensional array storage, the 1th (No. No. 0) element is used to start using the array. Father K, left child 2*k, right son 2*k+1. Then the traversal, the post-sequential traversal, the use of recursive way.

4. Build function, traverse function to write.

5. Write the code, submit the AC, recursive function, and remember to write the termination condition first.

6. This article is well written, readers can learn from it. http://blog.csdn.net/dogeding/article/details/52727239

7. This problem can be used for reference: Two tree storage, binary tree traversal.

Attach the AC code, compile the Environment dev-c++4.9.9.2

#include <stdio.h>

int n;
Char a[1024+10];
Char b[2048+10];

void Build (char *s,int N) {//Achievement code
Underlying structure
int i,j=0;
For (i= (1<<n); i<= (1<< (n+1)) -1;i++) {
b[i]=a[j++]== ' 0 '? B ': ' I ';
}

Bottom-up construction
for (i=n-1;i>=0;i--)
For (j= (1<<i); j<= (1<< (i+1)) -1;j++)
if (b[2*j]== ' B ' &&b[2*j+1]== ' B ')
b[j]= ' B ';
else if (b[2*j]== ' i ' &&b[2*j+1]== ' I ')
b[j]= ' I ';
Else
b[j]= ' F ';
}
void visit (int node) {//post-Traversal code
if (node> (1<< (n+1))-1)
Return
Visit (node*2);//Zuozi
Visit (node*2+1);//Right Sub-tree
printf ("%c", B[node]);//Root
}
int main () {
scanf ("%d", &n);
scanf ("%s", a);
Build (A,n);
Visit (1);
printf ("\ n");
return 0;
}


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.