22808_TreesandLevels

2022-5-16 18:22| 发布者: Hocassian| 查看: 21| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506976778800-Problem List-采集的数据-后羿采集器.html

Pro.ID

22808

Title

Trees and Levels

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22808

AC

0

Submit

5

Ratio

0.00%

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others)
  • 描述

    Trees are everywhere in Computer Science. Traditionally, trees are traversed from the root down, but in this problem you will be concerned with a level-by-level traversal of the tree. A level-order traversal of a tree prints the contents of each node in a given level in left to right order, and all nodes at level k are printed before any nodes at level k+1. For example, for the tree shown in Figure 2, the level-order traversal is 5, 4, 8, 11, 13, 4, 7, 2, 1.

    Your job is to read a specification of a binary tree and print out the level-order traversal. The specification is a series of nodes of the form ( n, s ) where n is a node number and s is a string representing the path from the root node. s will consis of a series of L's and R's, where L is for a left branch and R is for a right branch. For example, in the example above the node containing 13 is ( 13, RL ) and the node containing 2 is ( 2, LLR). The root node would be (5, ); there is no path string from the root since it is the root.

    A binary tree is completely specified if every node on all root-to-node paths in the tree is given a value exactly once. If the specification dose not specify a complete tree, then your program should display not complete instead of the level-order traversal.

    输入

    The input is a sequence of binary trees specified as described above. Each tree in a sequence consists of several pairs ( n, s ) as described above, separated by whitespace. The last entry in the tree is ( ). No whitespace appears between left and right parentheses. All nodes contain a positive integer. Every tree in the input will consist of at least one node and no more than 256 nodes.

    输出

    Description

    Trees are everywhere in Computer Science. Traditionally, trees are traversed from the root down, but in this problem you will be concerned with a level-by-level traversal of the tree. A level-order traversal of a tree prints the contents of each node in a given level in left to right order, and all nodes at level k are printed before any nodes at level k+1. For example, for the tree shown in Figure 2, the level-order traversal is 5, 4, 8, 11, 13, 4, 7, 2, 1.

    Your job is to read a specification of a binary tree and print out the level-order traversal. The specification is a series of nodes of the form ( n, s ) where n is a node number and s is a string representing the path from the root node. s will consis of a series of L's and R's, where L is for a left branch and R is for a right branch. For example, in the example above the node containing 13 is ( 13, RL ) and the node containing 2 is ( 2, LLR). The root node would be (5, ); there is no path string from the root since it is the root.

    A binary tree is completely specified if every node on all root-to-node paths in the tree is given a value exactly once. If the specification dose not specify a complete tree, then your program should display not complete instead of the level-order traversal.

    Input

    The input is a sequence of binary trees specified as described above. Each tree in a sequence consists of several pairs ( n, s ) as described above, separated by whitespace. The last entry in the tree is ( ). No whitespace appears between left and right parentheses. All nodes contain a positive integer. Every tree in the input will consist of at least one node and no more than 256 nodes.

    Output

    For each completely specified binary tree in the input, the level order traversal of that tree should be output. If the tree is no completely specified, i.e. some node in the tree is not given a value or a node is given more than one value, then the string not complete should be printed. Each traversal or not complete should appear on a separate line, corresponding to the order of the trees in the input.

    Sample Input

    (11,LL) (7,LLL) (8,R)
    (5,) (4,L) (13,RL) (2,LLR) (1,RRR) (4,RR) ()
    (3,L) (4,R) ()

    Sample Output

    5 4 8 11 13 4 7 2 1
    not complete

    Hint
    Source

    样例输入

    (11,LL) (7,LLL) (8,R)
    (5,) (4,L) (13,RL) (2,LLR) (1,RRR) (4,RR) ()
    (3,L) (4,R) ()

    样例输出

    5 4 8 11 13 4 7 2 1
    not complete

    提示


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部