Solitaire is a game played on a chessboard 8x8. The rows and columns of the chessboard are numbered from 1 to 8, from the top to the bottom and from left to right respectively.
There are four identical pieces on the board. In one move it is allowed to:
> move a piece to an empty neighboring field (up, down, left or right),
> jump over one neighboring piece to an empty field (up, down, left or right).
There are 4 moves allowed for each piece in the configuration shown above. As an example let's consider a piece placed in the row 4, column 4. It can be moved one row up, two rows down, one column left or two columns right.
Input:
Each of two input lines contains 8 integers a1, a2, ..., a8 separated by single spaces and describes one configuration of pieces on the chessboard. Integers a2j-1 and a2j (1 <= j <= 4) describe the position of one piece - the row number and the column number respectively. Process to the end of file.
Output:
The output should contain one word for each test case - YES if a configuration described in the second input line is reachable from the configuration described in the first input line in at most 8 moves, or one word NO otherwise.
Sample Input:
4 4 4 5 5 4 6 5
2 4 3 3 3 6 4 6
Sample Output
YES
题意:给你四个点的起始坐标,还有四个点的终点坐标;
在每一步中你可以让一个点往上下左右移动一格,如果移动一格后撞到其他的点上,你可以跳过这一格,既移动两格。
问是否能在最多八步完成。
//思路:我一开始想到是用一个九维数组来存它的转态,不过一直在爆内存;
//后来看了大佬们的博客后发现要用hash值来存,把四个点的坐标转换为一个8位数的数字就可以了;
//注意,转换数字时一定要先排序,否则会重复;
//再因为一些细节WA了几发后,终于A了
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include