Ultraviolet A the most distant state

Source: Internet
Author: User

The questions are as follows:

Problem

The most distant state

Input:Standard Input

Output:Standard output

 

The 8-puzzle is a square tray inwhich eight square tiles are placed. the remaining ninth square is uncovered. each tile has a number on it. A tile that is adjacent to the blank space can beslid into that space. A game consists of a starting state and a specified goal state. the starting state can be transformed into the goal state by sliding (moving) the tiles around. the 8-puzzle problem asks you Want to do the transformation inminimum number of moves.

 

2

8

3

 

 

 

1

2

3

1

6

4

=>

8

 

4

7

 

5

 

 

 

7

6

5

Start

 

 

 

Goal

 

However, our current problem is abit different. in this problem, given an initial state of the puzzle your areasked to discover a goal state which is the most distant (in terms of number ofmoves) of all the states reachable from the given state.


Input

The first line of the input filecontains an integer representing the number of test cases to follow. A blankline follows this line.


Each test case consists of 3 lines of 3 integers each representing the initial state of the puzzle. theblank space is represented by a 0 (zero). A blank line follows each test case.

 

Output

For each test case first outputthe puzzle number. the next 3 lines will contain 3 integers each representingone of the most distant states reachable from the given state. the next linewill contain the shortest sequence of moves that will transform the given Stateto that state. the move is actually the movement of the blank space representedby four ctions: U (up), L (left), D (down) and R (right ). after each testcase output an empty line.

 

Sample Input

1

2 6 4
1 3 7
0 5 8

Sample output

Puzzle #1
8 1 5
7 3 6
4 0 2
Uurddrullurrdlldrrululddruulddr


Eight Digital problems, find the target State farthest from the initial state and print out the path, solve it with BFs, the last state is the farthest state, and use hash to determine the weight.

The AC code is as follows:


Ultraviolet A the most distant state

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.