#P1087. [NOIP 2004 普及组] FBI 树
[NOIP 2004 普及组] FBI 树
Description
We can divide strings composed of 0 and 1 into three categories: an all-0 string is called a B string, an all-1 string is called an I string, and a string that contains both 0 and 1 is called an F string.
An FBI tree is a binary tree whose node types are F, B, and I. Given a binary string of length , an FBI tree can be constructed recursively as follows:
- Let be the root of , and set its type to be the same as the type of .
- If the length of is greater than 1, split in the middle into equal-length left and right substrings and . Construct the left subtree of from , and the right subtree of from .
Given a binary string of length , construct an FBI tree using the method above and output its postorder traversal sequence.
Input Format
The first line contains an integer .
The second line contains a binary string of length .
Output Format
A single string, i.e., the postorder traversal sequence of the FBI tree.
3
10001011
IBFBBBFIBFIIIFF
Hint
For 40% of the testdata, .
For all the testdata, .
This is the 3rd problem of NOIP 2004 Junior.
Translated by ChatGPT 5
京公网安备 11011102002149号