问题 E: 【排序】绝境求生
时间限制: 1 Sec 内存限制: 64 MB 提交: 4 解决: 4 [ ] [ ] [ ] [命题人: ]题目描述
The Eight Puzzle, among other sliding-tile puzzles, is one of the famous problems in artificial intelligence. Along with chess, tic-tac-toe and backgammon, it has been used to study search algorithms. The Eight Puzzle can be generalized into an M × N Puzzle where at least one of M and N is odd. The puzzle is constructed with MN − 1 sliding tiles with each a number from 1 to MN − 1 on it packed into a M by N frame with one tile missing. For example, with M = 4 and N = 3, a puzzle may look like: Let's call missing tile 0. The only legal operation is to exchange 0 and the tile with which it shares an edge. The goal of the puzzle is to find a sequence of legal operations that makes it look like: The following steps solve the puzzle given above. Given an M × N puzzle, you are to determine whether it can be solved.
样例输入
3 31 0 34 2 57 8 64 31 2 54 6 911 8 103 7 00 0
样例输出
YESNO分析:不知道之前什么时候水过这题,去POJ抄来了题解。。。一个树状数组求逆序对的题。。
#include#include #include #include #include #include #include #include #include #include