UVa Blocks Problem (Super Simulation)

Source: Internet
Author: User

101-the Blocks Problem

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=37

Background

Many areas of Computer, abstract domains for both analytical and empirical studies. For example, a early AI study of Planning and Robotics (STRIPS) used a blocks world in which a robot arm performed tasks I Nvolving the manipulation of blocks.

In this problem you'll model a simple blocks world under certain rules and constraints. Rather than determine to achieve a specified state, you'll ' program ' a robotic arm to respond to a limited set of Commands.

The Problem

The problem is to parse a series of commands, instruct a robot arm in, to manipulate blocks, lie on a flat tabl E. Initially there are n blocks on the table (numbered from 0 ton-1) with blocks bI adjacent to block Bi +1 for all

As shown in the diagram below:

Figure: Initial Blocks World

The valid commands for the robot arm, that manipulates blocks are:

Move a onto b

Where a and b are block numbers, puts blocks a onto block b over returning any blocks That is are stacked on the top of blocks a and b to their initial positions.

Move a over b

Where a and b are block numbers, puts blocks a onto the top of the stack containing block b, after returning any blocks that are stacked on the top of the block a to their initial.

Pile a onto b

Where a and b are block numbers, moves the pile of blocks consisting of blocks a, and any Blocks that are stacked above blocks a, onto block b. All blocks in the top of blocks b are moved to their initial positions prior to the pile. The blocks stacked above block a retain their order when moved.

Pile a over b

Where a and b are block numbers, puts the pile of blocks consisting of blocks a, and any blocks That's are stacked above block a, onto "top of the" stack containing block b. The blocks stacked above block a retain their original order when moved.

Quit

Terminates manipulations in the blocks world.

Any command in which a = b or in which a and b are in the same stack of blocks is a I Llegal command. All illegal commands should is ignored and should have no affect on the configuration of blocks.

The Input

The input begins with a is integer n on a line by itself representing the number of blocks in the blocks world. You are assume that 0 < n < 25.

The number of blocks is followed by a sequence of blocks commands, one command per line. Your program should process all commands until the quit command is encountered.

You may assume so all commands would be the form specified above. There would be no syntactically incorrect commands.

The Output

The output should consist of the final state of the blocks world. Each original block position numbered I (

where n is the number of blocks) should appear followed immediately by a colon. If there is at least an IT, the colon must be followed by one space, followed by a list of blocks that appear Ked in and position with the each block number separated from the other blocks numbers by a. Don ' t put any trailing spaces in a line.

There should be one line of output for each block position (i.e., n lines to output where n is the Integ Er on the the "I" input).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.