Type: Default 1000ms 256MiB

L2-4 麻烦的二叉搜索树

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

题目背景

给一个二叉搜索树添加结点时,如果树空,则该结点为根结点,否则与根结点比较,如果小于等于根结点,则进入左子树,如果大于根结点,进入右子树。

现在给你一些整数,要求你建一棵二叉搜索树并且打印出来。

输入

第一行一个数字T表示有TT组数据 每组数据给一个NN表示结点数量 接下来NN个数A1,A2,,AnA_1,A_2,\dots,A_n表示每个结点权值。

输出

每个结点用 [下标, 权值] 表示,每一行输出一个结点,先输出左子树的内容,然后输出根,接着输出右子树的内容。

具体格式见样例

样例

2
5
1 2 3 4 5
5
9 7 8 10 11
Case 1:
[1, 1]-|
       |-[2, 2]-|
                |-[3, 3]-|
                         |-[4, 4]-|
                                  |-[5, 5]
Case 2:
       |-[2, 7]-|
       |        |-[3, 8]
[1, 9]-|
       |-[4, 10]-|
                 |-[5, 11]
3
11
72 75 157 95 80 85 146 81 37 56 92

19
88 196 97 36 186 157 77 193 159 89 85 165 111 63 96 170 52 149 135

Case 1:
        |-[9, 37]-|
        |         |-[10, 56]
[1, 72]-|
        |-[2, 75]-|
                  |                    |-[5, 80]-|
                  |                    |         |         |-[8, 81]
                  |                    |         |-[6, 85]-|
                  |                    |                   |-[11, 92]
                  |          |-[4, 95]-|
                  |          |         |-[7, 146]
                  |-[3, 157]-|
Case 2:
        |-[4, 36]-|
        |         |                    |-[17, 52]
        |         |         |-[14, 63]-|
        |         |-[7, 77]-|
        |                   |-[11, 85]
[1, 88]-|
        |                    |-[10, 89]-|
        |                    |          |-[15, 96]
        |          |-[3, 97]-|
        |          |         |                     |-[13, 111]-|
        |          |         |                     |           |           |-[19, 135]
        |          |         |                     |           |-[18, 149]-|
        |          |         |          |-[6, 157]-|
        |          |         |          |          |-[9, 159]-|
        |          |         |          |                     |-[12, 165]-|
        |          |         |          |                                 |-[16, 170]
        |          |         |-[5, 186]-|
        |          |                    |-[8, 193]
        |-[2, 196]-|

数据范围

  • 1N,Ai2001 \leq N,A_i \leq 200

2023团体程序设计天梯赛选拔赛

Not Attended
Status
Done
Rule
IOI
Problem
14
Start at
2023-3-19 14:00
End at
2023-3-19 17:00
Duration
3 hour(s)
Host
Partic.
46