No.392 Traverse the Binary Tree
タグ : / 解いたユーザー数 292
作問者 :
horiesiniti
/ テスター :
37zigen
Problem Statement
Binary Tree
As shown in the figure above, the nodes of a binary tree are numbered in a regular pattern starting from 0, up to 4094.
Taking node 0 as level 0, nodes 1, 2 as level 1, nodes 3, 4, 5, 6 as level 2, and so on, all nodes at level 11 are leaves, and every other node has two nodes on the level below.
Traverse this tree and answer the route from node 0 to node $A_i$.
Print $L$ when going to the lower left and $R$ when going to the lower right.
Input
$m$ $A_1$ $\dots$ $A_m$
First, a number $m$ is given on one line.
$0 \lt m \le 4094$
Each of the following $m$ lines contains
a single number $ 0 \lt A_i \le 4094$
Starting from node 0, print the route to reach node $A_i$, one per line.
L means moving to the lower left and R means moving to the lower right.
For example, moving to 10 gives LRR
moving to 3 gives LL
moving to 13 gives RRL
and so on. For each input, output the route on one line as $Ci$.Output
$C_1$ $\dots$ $C_m$Print a newline at the end.
Sample
Sample 1
Input
2 21 14
Output
LRRL RRR
Both 21 and 14 can be seen by extending the figure.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。