#P2274. [HNOI2002] 树的排序
[HNOI2002] 树的排序
Description
- The empty tree is numbered , and the tree with only the root node is numbered .
- Let be any non-negative integer. Then the number of any tree with nodes is smaller than the number of any tree with nodes.
- Let be two trees with the same number of nodes (with ). The number of is smaller than that of if and only if one of the following holds:
- The number of the left subtree of is smaller than the number of the left subtree of .
- The numbers of the left subtrees of and are equal (that is, the left subtrees of and have the same shape), and the number of the right subtree of is smaller than the number of the right subtree of .
- Following the usual rule, the numbers are consecutive non-negative integers. Each tree corresponds to a unique number, and each non-negative integer corresponds to a unique tree.
(Note: all trees mentioned above are binary trees.)
Input Format
A single line with an integer , .
For of the testdata, the number of nodes in the tree does not exceed three.
Output Format
A single line: the binary tree corresponding to number . Output as follows:
- If it is a one-node binary tree, output .
- If the left and right subtrees are and , and their respective outputs are and , then output ; when the left subtree is empty, output ; when the right subtree is empty, output .
20
((X)X(X))X
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号