#abc246e. E - Bishop 2
E - Bishop 2
Score : points
问题描述
我们有一个 的棋盘。令 表示该棋盘从上到下第 行、从左到右第 列的格子。
棋盘由 个字符串 描述。字符串 的第 个字符 表示如下含义:
- 若
.
,表示格子 为空。 - 若
#
,表示格子 被一个白色兵占据,且不能移动或移除。
我们在格子 上放置了一个白色象(即主教)。
根据国际象棋规则(见注释),求从 移动这个象到 所需的最小步数。
如果无法移动到 ,则输出 -1
。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have an chessboard. Let denote the square at the -th row from the top and -th column from the left of this board.
The board is described by strings .
The -th character of the string , , means the following.
- If
.
, the square is empty. - If
#
, the square is occupied by a white pawn, which cannot be moved or removed.
We have put a white bishop on the square .
Find the minimum number of moves needed to move this bishop from to according to the rules of chess (see Notes).
If it cannot be moved to , report -1
instead.
Notes
A white bishop on the square can go to the following positions in one move.
-
For each positive integer , it can go to if all of the conditions are satisfied.
- The square exists in the board.
- For every positive integer , is not occupied by a white pawn.
-
For each positive integer , it can go to if all of the conditions are satisfied.
- The square exists in the board.
- For every positive integer , is not occupied by a white pawn.
-
For each positive integer , it can go to if all of the conditions are satisfied.
- The square exists in the board.
- For every positive integer , is not occupied by a white pawn.
-
For each positive integer , it can go to if all of the conditions are satisfied.
- The square exists in the board.
- For every positive integer , is not occupied by a white pawn.
Constraints
- is a string of length consisting of
.
and#
. -
.
-
.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
5
1 3
3 5
....#
...#.
.....
.#...
#....
Sample Output 1
3
We can move the bishop from to in three moves as follows, but not in two or fewer moves.
- $(1,3) \rightarrow (2,2) \rightarrow (4,4) \rightarrow (3,5)$
Sample Input 2
4
3 2
4 2
....
....
....
....
Sample Output 2
-1
There is no way to move the bishop from to .
Sample Input 3
18
18 1
1 18
..................
.####.............
.#..#..####.......
.####..#..#..####.
.#..#..###...#....
.#..#..#..#..#....
.......####..#....
.............####.
..................
..................
.####.............
....#..#..#.......
.####..#..#..####.
.#.....####..#....
.####.....#..####.
..........#..#..#.
.............####.
..................
Sample Output 3
9
update @ 2024/3/10 10:33:42