#P14114. [IAMOI R4] 皇后
[IAMOI R4] 皇后
Description
Little T likes to play chess, so Little Y decides to give her a challenge.
Given an chessboard, Little Y places a queen at position . Little T needs to move the queen to in as few moves as possible.
To increase the difficulty, Little Y will place an obstacle on a single square, other than the starting and ending squares. The queen cannot pass through this obstacle. Little Y wants to place this obstacle to maximize the number of moves Little T needs.
Assuming both players adopt their optimal strategies, what is the number of moves Little T will take?
: The queen is a piece in international chess. In a single move, it can move any number of squares in one of the eight directions (horizontally, vertically, and diagonally).
Input Format
This problem contains multiple test cases.
The first line of the input contains an integer , representing the number of test cases.
This is followed by test cases. For each test case, a single line contains six positive integers: .
Output Format
For each test case, output a single line containing an integer, which is the answer.
3
2 2 1 1 1 1
3 3 1 1 3 3
2 5 1 1 1 5
0
2
3
Hint
【Sample Explanation】
For the first test case, the queen is already at the target position, so 0 moves are needed.
For the second test case, Little Y might place the obstacle at . Little T can then move the queen first to and then to , taking 2 moves.
For the third test case, Little Y might place the obstacle at . Little T can then move the queen first to , then to , and finally to , taking 3 moves.
【Data Constraints】
| Test Case # | Special Properties | ||
|---|---|---|---|
| None | |||
| ^ | |||
| ^ | |||
| ^ | ^ | ||
| None | |||
| ^ | |||
For all test cases, it is guaranteed that: , .
京公网安备 11011102002149号