描述:
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
翻译:
接龙
描述:接龙是一个在8×8的棋盘上玩的游戏。棋盘的行和列被标记了数字1到8,从顶部到底部,从左边到右边。
在板子上面有四个棋子。在一次移动中被允许:
·移动一个棋子到空的相邻的地方(上下左右)
·可以跳过一个相邻的地方到空的地方(上下左右)
对于每个棋子有四次移动的机会。举个例子,让我们考虑一个棋子被放置在第四行第四列。他能够被移动到上面一行,下面两行,左面一行,右面两行。
写一个这样的程序:
·从标准输入中读入两个棋盘。
·证明是否可以从第一个棋盘里移动到第二个棋盘最多需要8次
·写出标准输出的从第一个棋盘里移动到第二个棋盘最多需要8次
结果
输入:
每两行输入包括8个整数a1,a2,.....a8被单独的空间分出来的并且描述了一个棋盘上的棋子。整数a2j-1和a2j(1<=j<=4)描述了一个棋子的位置--所在的行数和列数。
输出:
输出应该包含一个单词YES如果这个棋盘能够描述输入的从第一个棋盘里移动到第二个棋盘最多需要8次,否则就输出NO。
样例输入:
4 4 4 5 5 4 6 5
2 4 3 3 3 6 4 6
样例输出:
YES