#P14626. [2018 KAIST RUN Fall] Fake Plastic Trees
[2018 KAIST RUN Fall] Fake Plastic Trees
题目描述
is a recursive structure, which is either:
- . Empty tree is denoted as and has a size of 0.
- . Non-empty tree is denoted as a pair of two trees , where is called of , and is called of . If , then we call such a . Leaf has a size of 1, and non-leaf has a size of , where is the size of , and is the size of .
A non-empty tree is a , if the tree is . Formally, Let . If or holds, then is a Fake Plastic Tree.
In computer science, trees are commonly used as a data structure, and they are stored in a memory. At first, there are no trees in the memory, and only an imaginary exists (which corresponds to empty tree, ). You can allocate a tree in the memory, by setting and as either a null pointer or a pointer of an existing tree. Then, the memory is extended by adding into its structure. Note that pointer can be described as a small integer, reducing the need for explicitly storing the whole tree.
Formally, memory is an inductive structure, which at first contains only empty tree . (). You can expand the memory with following operation , where . If a tree is inserted in -th stage, then it has the . For a tree with index , their subtrees can be represented as a pair of integer in range .
Your task is to construct a memory , which satisfies the following:
- Every tree in is either empty or Fake Plastic Tree.
- has at most 125 non-empty trees.
- There exists a tree , where holds. is an integer, and is given as an input.
输入格式
The first line contains a single integer , the number of test cases. ()
In the next lines, a single integer is given, which indicates the number of leaves your tree should contain. ()
输出格式
For each case, you should print lines, where is the number of non-empty trees in . ().
In the first line, you should print single integer .
In the next lines, you should print two space-separated integer , which indicates the index of left subtree and right subtree for a tree with index . ().
In the -th line, you should print , the index of the tree which contains nodes. ().
It is guaranteed that an answer always exists under the given condition.
4
1
2
3
4
1
-1 -1
0
3
-1 -1
-1 -1
0 1
2
3
-1 -1
0 0
1 0
2
5
-1 -1
0 0
0 0
2 1
1 2
3
提示
:::align{center}

Illustration of output for in the example. :::