HDU-1043 Eight(BFS)
来源:互联网 发布:2011网络春晚大张伟 编辑:程序博客网 时间:2024/05/29 17:20
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:
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:
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.
1 2 3 4 5 6 7 8 9 10 11 1213 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 1213 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.
1 2 3
x 4 6
7 5 8
is described by this list:
1 2 3 x 4 6 7 5 8
2 3 4 1 5 x 7 6 8
ullddrurdllurdruldr
阅读全文
0 0
- HDU-1043 Eight(BFS)
- HDU 1043 Eight 反向BFS
- hdu 1043 Eight(BFS经典)
- HDU 1043 Eight(BFS)
- hdu 1043 Eight 双向BFS/A*算法
- HDU 1043 Eight(BFS+康拓展开)
- hdu 1043 Eight(bfs+康托)
- [BFS+康托展开]Hdu 1043 Eight
- HDU 1043 && POJ 1077 Eight bfs || 双向bfs || A*搜索
- hdu 1043 eight 八数码问题 bfs 和 A*
- HDU 1043 Eight(bfs+康托展开)
- HDU 1043 Eight(BFS打表+状态去重)
- HDU 1043 Eight(经典八数码)(BFS+STL)
- POJ 1077 Eight & HDU 1043 Eight(康托展开+BFS)
- HDU 3567 Eight II 预处理+bfs+hash
- hdu 1043 Eight
- HDU 1043 Eight
- 周赛 HDU 1043 Eight
- Android开发 之 动态显示和隐藏状态栏和导航栏
- java在标签对内赋值
- 国家图书馆提示“对不起,系统检测您还没有安装PDF阅读器”的解决方法 | 国家电子图书馆
- dijkstra拓展(规划最短航线问题)
- cookie的删除与替换
- HDU-1043 Eight(BFS)
- VTK Chart坐标轴
- 作业代码
- Json返回通用对象,工具类
- Struts的运行原理及开发流程
- 列表
- linux学习笔记(一)
- UVA 12563 Jin Ge Jin Qu hao
- 【java笔记】day05