#P10713. 【MX-X1-T1】「KDOI-05」简单的无限网格问题
【MX-X1-T1】「KDOI-05」简单的无限网格问题
Background
Original link: https://oier.team/problems/X1A。
Problem Description
X is taking part in the KDOI Robot Championship.
The arena is an infinite grid. X's robot starts at . He needs to perform several operations to move the robot to ().
In the -th operation, X may choose one of four directions: up, down, left, or right, and choose a positive integer , then make the robot move steps in that direction.
Unfortunately, X's robot has some bugs, so his operations must satisfy the following restriction, otherwise the robot will explode immediately:
- For the -th operation, if is odd, then is also odd; if is even, then is also even.
Please help X compute the minimum number of operations needed to make his robot reach .
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , the number of test cases.
For each test case, the input contains one line with two positive integers .
Output Format
For each test case, output one integer per line, representing the answer. It can be proven that X's robot can always reach in a finite number of steps.
3
8 7
999999 1000000
3 3
2
2
3
Hint
Sample Explanation
For the first test case, the robot can move as follows:
A total of operations are needed. It can be proven that there is no better sequence of operations.
Constraints
This problem uses bundled testdata.
| Subtask ID | Score | Special Property | |
|---|---|---|---|
| None | |||
| have the same parity | |||
| None |
For all data (): , .
Translated by ChatGPT 5