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.

SampleInput

2  3  4  1  5  x  7  6  8

SampleOutput

ullddrurdllurdruldr
就是给你一个序列,然后要你通过四种移动方式,回到最初的序列,输出答案,题目有SPJ,无需输出最优方法。
这道题可谓是搜索中的精髓了,最开始我就是一个简单的双向搜索,结果TLE了,看了网上的博客加了剪枝之后过了。
但是后来和队友聊这题,发现这道题的解题思路不止一种,队友说有八种

然后找到一篇博客,里面一共讲了八种解法,应该是很全面的。
博客链接:https://www.cnblogs.com/zufezzt/p/5659276.html至于我的代码就没什么好讲的了,确实用双向BFS加剪枝可以AC这道题,但这道题的精髓远远不在于此,也见识到了自己的学识浅薄。我也道不出个所以然,所以这道题我就不详细讲了。
还是那句话以梦为马,不负韶华。

最新文章

  1. google书签找回
  2. JDK里面的JRE是什么
  3. HDU 5878 I Count Two Three (打表+二分查找) -2016 ICPC 青岛赛区网络赛
  4. guava学习--File
  5. jquery源码学习之extend
  6. my linux tech object
  7. 深入浅出 - Android系统移植与平台开发(五)- 编译Android源码(转)
  8. java下载网络图片
  9. JSF 2 panelGrid example
  10. C++ STL之deque的基本操作
  11. 本地或者是koala软件编译less文件为css
  12. uva10622 Perfect P-th Powers
  13. Android 的权限设置大全
  14. sql server 2012 数据库还原方法
  15. hdu 4444 Walk (离散化+建图+bfs+三维判重 好题)
  16. 【codeforces 718 C&D】C. Sasha and Array&D. Andrew and Chemistry
  17. 跟大家谈一谈:涛舅舅家的微信域名检测api的心路历程
  18. Latex所有常用数学符号整理
  19. golang 打包,交叉编译,压缩
  20. Vue常见指令

热门文章

  1. Docker入门-搭建docker私有仓库
  2. 面试java后端面经_3
  3. vue 异步加载远程组件(支持编译less语法)
  4. R 实用命令 1
  5. springboot中的外界jar的引入:
  6. MSIL实用指南-struct的生成和操作
  7. 【spring-boot 源码解析】spring-boot 依赖管理
  8. Python--高阶函数、函数嵌套、名称空间及变量作用域、闭包、装饰器
  9. HTML(七)CSS
  10. JavaScript label语句