题目
总时间限制: 5000ms 单个测试点时间限制: 1000ms 内存限制: 65536kB
描述
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.
Write a program that:
reads two chessboard configurations from the standard input,
verifies whether the second one is reachable from the first one in at most 8 moves,
writes the result to the standard output.
输入
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.
输出
The output should contain one word 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.
样例输入
4 4 4 5 5 4 6 5
2 4 3 3 3 6 4 6
样例输出
YES
宽搜代码
#include <bits/stdc++.h>
using namespace std;
const int d[4][2]={
{
0,-1},{
-1,0},{
0,1},{
1,0}};//左上右下四个方向
struct node{
//每个棋的坐标
int x,y;
bool operator<(const node& b)const{
//排序用
if(x==b.x)return y<b.y;
return x<b.x;
}
};
struct chesss{
int step,id[2];//步数
node piece[2][4];//起始和目标四个子的位置
bool board[2][9][9];//起始和目标的布局
chesss(){
//无参构造函数
step=0;
memset(board,0,sizeof(board));//初始化
}
void makeid(int x){
//布局(各棋子的坐标)转换成8位唯一的id
sort(piece[x],piece[x]+4);//排序
id[x]=0;
for(int i=0;i<4;i++)
id[x]=id[x]*100+piece[x][

最低0.47元/天 解锁文章
1060

被折叠的 条评论
为什么被折叠?



