Eight
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 21024 Accepted Submission(s): 5644
Special Judge
Problem Description
The 15-puzzle has been aroundforover100 years; even if you don't know itbythatname, you've seen it. It is constructed with15 sliding tiles, each with a numberfrom1to15onit, and all packed into a 4by4 frame with one tile missing. Let's call the missing tile 'x'; the object ofthe puzzle isto arrange the tiles so that they are ordered as:
123456789101112131415 x
wherethe only legal operation isto exchange 'x' with one ofthe tiles with which it shares an edge. As an example, the following sequence of moves solves a slightly scrambled puzzle:
123412341234123456785678567856789 x 1012910 x 129101112910111213141115131411151314 x 15131415 x
r-> d-> r->
The letters inthe previous row indicate which neighbor ofthe 'x' tile is swapped withthe 'x' tile at each step; legal values are 'r','l','u' and 'd', for right, left, up, and down, respectively.
Not all puzzles can be solved; in1870, a man named Sam Loyd was famous for distributing an unsolvable versionofthe puzzle, and
frustrating many people. In fact, all you have to do to make a regular puzzle into an unsolvable one isto swap two tiles (not counting the missing 'x' tile, of course).
In this problem, you will write a program for solving the less well-known 8-puzzle, composed of tiles on a three by three
arrangement.
Input
You will receive, several descriptions of configuration ofthe8 puzzle. One description is just a listofthe tiles in their initial positions, withthe rows listed from top to bottom, andthe tiles listed from left to right within a row, wherethe tiles are represented by numbers 1to8, plus 'x'. For example, this puzzle
123
x 46758is described by this list:
123 x 46758
Output
You will print to standard output either theword ``unsolvable'', ifthe puzzle has no solution, or a string consisting entirely ofthe letters 'r', 'l', 'u' and 'd' that describes a series of moves that produce a solution. The string should include no spaces and start atthebeginningofthe line. Do not print a blank line between cases.
Sample Input
23415 x 768
Sample Output
ullddrurdllurdruldr
Source
South Central USA 1998 (Sepcial Judge Module By JGShining)
Recommend
JGShining