矩阵的轮替的一个算法的求解的办法,怎么利用C语言的程序的设计的思路去实现的?

Problem Description
The 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15 sliding tiles, each with a number from 1 to 15 on it, and all packed into a 4 by 4 frame with one tile missing. Let's call the missing tile 'x'; the object of the puzzle is to arrange the tiles so that they are ordered as:

1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 x

where the only legal operation is to exchange 'x' with one of the tiles with which it shares an edge. As an example, the following sequence of moves solves a slightly scrambled puzzle:

1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
5 6 7 8 5 6 7 8 5 6 7 8 5 6 7 8
9 x 10 12 9 10 x 12 9 10 11 12 9 10 11 12
13 14 11 15 13 14 11 15 13 14 x 15 13 14 15 x
r-> d-> r->

The letters in the previous row indicate which neighbor of the 'x' tile is swapped with the '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; in 1870, a man named Sam Loyd was famous for distributing an unsolvable version of the puzzle, and
frustrating many people. In fact, all you have to do to make a regular puzzle into an unsolvable one is to 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 of the 8 puzzle. One description is just a list of the tiles in their initial positions, with the rows listed from top to bottom, and the tiles listed from left to right within a row, where the tiles are represented by numbers 1 to 8, plus 'x'. For example, this puzzle

1 2 3
x 4 6
7 5 8

is described by this list:

1 2 3 x 4 6 7 5 8

Output
You will print to standard output either the word ``unsolvable'', if the puzzle has no solution, or a string consisting entirely of the letters 'r', 'l', 'u' and 'd' that describes a series of moves that produce a solution. The string should include no spaces and start at the beginning of the line. Do not print a blank line between cases.

Sample Input
2 3 4 1 5 x 7 6 8

Sample Output
ullddrurdllurdruldr

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问

相似问题

1
用C 语言编程,实现矩阵(3行3列)的转置(即行列互换)
1
如何用C语言实现求给定矩阵的逆矩阵?
1
C语言的函数算法去解决一个矩阵的问题,涉及到大数的计算怎么实现的?
0
矩阵三角形延展占用的行列坐标构图的问题,如何利用C语言的方式求解的?
0
三角形矩阵的求和的算法,如何利用C语言的办法计算三角形和
0
采用C语言的办法计算矩阵的共约数的问题的解决
1
矩阵里元素交换的一个算法,如何利用C语言的编程的技术实现的办法
0
运用C语言是如何解决这里的矩阵的一个转换颠倒的算法的?具体的思路
0
矩阵 的Hadamard积的数据结构的算法,采用C语言编程技术如何实现的思路
0
矩阵数字的一个路径的算法,怎么利用C语言编写程序的方式实现的
0
正方形的矩阵的一个算法的问题思路,用C语言的方式去计算怎么做
0
最短矩阵的移动距离的一个算法问题怎么利用C语言的程序的设计来解决的
0
一个用矩阵保存的分数的算法,计算2位小数,怎么利用C语言实现
0
和谐的矩阵的判断算法,怎么实现对矩阵的判断用C语言的程序的设计的办法
0
一个赢面的概率的矩阵计算,怎么利用C语言的程序的设计的办法来实现的
0
矩阵的优化的一个算法的问题怎么实现,用C语言的程序的编程的技术的实现
0
一个矩形构成的矩阵的算法问题,如何利用C程序的设计的语言的方式实现呢
0
运用二维数矩阵的数据结构解决的这个问题的算法,怎么采用C语言程序的办法来实现代码?
0
数组的矩阵的转移的算法,怎么采用C语言的程序的计算的方式来实现的
0
MxN的二维矩阵上的最小点的寻找,怎么利用C程序的语言的设计的算法实现的呢