21730_RECONSTRUCTINGTREES

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

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

Pro.ID

21730

Title

RECONSTRUCTING TREES

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 3000/1000 MS (Java/Others)     Memory Limit: 131072/65536 K (Java/Others)
  • 描述

    It is very easy to produce the various traversals of a binary tree, however this problem requires you to produce the tree from the traversals. Specifically, given the pre-order and in-order traversals of a binary tree (not necessarily a binary search tree), reconstruct, if possible, the original tree.
    For instance, the following tree will produce the traversals shown
          E
         / \
        D   F
       /     \
      B       G
     / \       \
    A   C       I
               / \
              H   K
                 /
                J
    Preorder : EDBACFGIHKJ
    Inorder  : ABCDEFGHIJK
    Postorder: ACBDHJKIGFE

    输入

    Input will consist of representations of several trees, each on a single line, and terminated by a #. Each line will consist of two strings of up to 26 unique uppercase letters in the form
    <pre-order> <space> <in-order>.
    You can assume that the two strings will be permutations of each other.

    输出

    Description
    It is very easy to produce the various traversals of a binary tree, however this problem requires you to produce the tree from the traversals. Specifically, given the pre-order and in-order traversals of a binary tree (not necessarily a binary search tree), reconstruct, if possible, the original tree.
    For instance, the following tree will produce the traversals shown
          E
         / \
        D   F
       /     \
      B       G
     / \       \
    A   C       I
               / \
              H   K
                 /
                J
    Preorder : EDBACFGIHKJ
    Inorder  : ABCDEFGHIJK
    Postorder: ACBDHJKIGFE
    Input
    Input will consist of representations of several trees, each on a single line, and terminated by a #. Each line will consist of two strings of up to 26 unique uppercase letters in the form
    <pre-order> <space> <in-order>.
    You can assume that the two strings will be permutations of each other.
    Output
    Output will consist of the post-order traversal of the reconstructed tree if possible, otherwise the words 'Invalid tree'.
    Sample Input
    EDBACFGIHKJ ABCDEFGHIJK
    #
    Sample Output
    ACBDHJKIGFE
    Source

    样例输入

    EDBACFGIHKJ ABCDEFGHIJK
    #

    样例输出

    ACBDHJKIGFE

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部