22806_BuildingBlocks

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

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

Pro.ID

22806

Title

Building Blocks

Title链接

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

AC

2

Submit

3

Ratio

66.67%

时间&空间限制

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

    Artificial Intelligence is a mysterious and glamorous field. Little do most people know that AI can often be like child's play. Consider robotics, where research projects focus on making robots play with toys. Although any four year old child can do this easily, it can be very hard for a robot.

    In this problem your program has to interpret and execute a series of commands in a very simple robot planning language. This language is designed to deal with a blocks world, consisting of n blocks numbered 0 to n-1, initially laid side by side. Such a world is shown in Figure 1.

    The planning language is designed to instruct a robot to move the blocks around, using the following commands ( a and b are block numbers such that 0 ≤ a, b < n ):

    move a onto b

    Puts block a on top of block b, after returning any blocks that were stacked on a and b to their original positions.

    move a over b

    Puts block a on top of the pile on block b, after returning any blocks that were stacked on a to their original positions. Retains the order of the b pile.

    pile a onto b

    Puts the pile of blocks on top of ( and including ) block a on top of block b, after returning any blocks that were stacked on b to their original positions. Retains the order of the a pile.

    pile a over b

    Puts the pile of blocks on top of ( and including ) block a on top of the pile of block b. Retains the order of the a and b piles.

    quit

    Terminates the planning program.

    Your job is to ececute these commands in order and display the resulting positions of all of the blocks. Any command in which a=b or in which a and b are in the same stack of blocks is an illegal command and should be ignored. Illegal command should not affect the final block positions.

    输入

    The input begins with an integer n on a line by itself representing the number of blocks. You may assume that 0 < n < 25. The number of blocks is followed by a sequence of block command, one command per line. Your program should process all commands until the quit command is encountered.

    输出

    Description

    Artificial Intelligence is a mysterious and glamorous field. Little do most people know that AI can often be like child's play. Consider robotics, where research projects focus on making robots play with toys. Although any four year old child can do this easily, it can be very hard for a robot.

    In this problem your program has to interpret and execute a series of commands in a very simple robot planning language. This language is designed to deal with a blocks world, consisting of n blocks numbered 0 to n-1, initially laid side by side. Such a world is shown in Figure 1.

    The planning language is designed to instruct a robot to move the blocks around, using the following commands ( a and b are block numbers such that 0 ≤ a, b < n ):

    move a onto b

    Puts block a on top of block b, after returning any blocks that were stacked on a and b to their original positions.

    move a over b

    Puts block a on top of the pile on block b, after returning any blocks that were stacked on a to their original positions. Retains the order of the b pile.

    pile a onto b

    Puts the pile of blocks on top of ( and including ) block a on top of block b, after returning any blocks that were stacked on b to their original positions. Retains the order of the a pile.

    pile a over b

    Puts the pile of blocks on top of ( and including ) block a on top of the pile of block b. Retains the order of the a and b piles.

    quit

    Terminates the planning program.

    Your job is to ececute these commands in order and display the resulting positions of all of the blocks. Any command in which a=b or in which a and b are in the same stack of blocks is an illegal command and should be ignored. Illegal command should not affect the final block positions.

    Input

    The input begins with an integer n on a line by itself representing the number of blocks. You may assume that 0 < n < 25. The number of blocks is followed by a sequence of block command, one command per line. Your program should process all commands until the quit command is encountered.

    Output

    The output should consist of the final state of the blocks world. Each original block position numbered i ( 0 ≤ i < n where n is the number of blocks) should appear followed immediately by a colon, a single space, and a list of blocks that appear stacked in that position with each block number separated from other block numbers by a single space. There should be one line of output for each block position.

    Sample Input

    10
    move 9 onto 1
    move 8 over 1
    move 7 over 1
    move 6 over 1
    pile 8 over 6
    pile 8 over 5
    move 2 over 1
    move 4 over 9
    quit

    Sample Output

    0: 0
    1: 1 9 2 4
    2:
    3: 3
    4:
    5: 5 8 7 6
    6:
    7:
    8:
    9:

    Source

    样例输入

    10
    move 9 onto 1
    move 8 over 1
    move 7 over 1
    move 6 over 1
    pile 8 over 6
    pile 8 over 5
    move 2 over 1
    move 4 over 9
    quit

    样例输出

    0: 0
    1: 1 9 2 4
    2:
    3: 3
    4:
    5: 5 8 7 6
    6:
    7:
    8:
    9:

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部