#P7354. 「PMOI-1」立方骑士
「PMOI-1」立方骑士
Description
lhm has built a chessboard of size . You, as White, will fight against Black. Black has only one king, and the king’s position will not move. lhm has an unlimited number of knights. Now you need to find the minimum number of knights required to checkmate the Black king. The checkmate standard is defined as: the Black king cannot move without being captured.
More formally: on an board there is a king. You need to place as few knights as possible on the board such that for every position that the king can reach in exactly one step and is still inside the board, there exists at least one knight that can reach it in exactly one step.
Piece movements:
- The king can move one square each step in eight directions: up, down, left, right, up-left, up-right, down-left, down-right.
- The knight moves the same as in standard chess: each move is an L-shape (i.e., the diagonal of a rectangle; see the sample). Note that there is no “blocked knight” rule: as long as it does not leave the board and follows the L-shape, there are no other restrictions.
lhm is not good at this, so he asks smart you to help him complete this task.
Input Format
This problem contains multiple test cases.
The first line contains an integer , the number of test cases.
For each test case, one line contains four integers , representing the board size and the coordinates of the Black king.
Output Format
Output lines in total. Each line contains one integer, the minimum number of knights needed.
1
8 8 1 1
2
2
10 9 1 9
999 999 999 2
2
3
Hint
[Sample 1 Explanation]

On a board like the one above, represents the Black king, represents a White knight, and represents squares that a knight can reach (among them, the at blocks and , and the at blocks ). As shown above, has already been completely trapped, so two knights are enough. It can be proven that two knights is the minimum.
[Constraints]
- For of the testdata, the king’s initial position is guaranteed to be on the outermost ring of the board.
- For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号