高尔夫 2AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)You are given integers $A, B, X, Y$.
给定整数 $A, B, X, Y$。AI (CI翻译)
A piece is placed on a two-dimensional plane. Initially, the piece is at coordinates $(0, 0)$.
在二维平面上放置一个棋子。初始时,棋子位于坐标 $(0, 0)$。AI (CI翻译)
You can perform the following operation zero or more times:
可以进行零次或多次以下操作:AI (CI翻译)
- Let
$(x, y)$be the current coordinates of the piece. Move the piece to coordinates$(x', y')$satisfying one of the following conditions: $|x - x'| = A$and$|y - y'| = B$$|x - x'| = B$and$|y - y'| = A$
- 设棋子当前坐标为
$(x, y)$。将棋子移动到满足以下任一条件的坐标$(x', y')$:$|x - x'| = A$且$|y - y'| = B$$|x - x'| = B$且$|y - y'| = A$
Determine whether it is possible to move the piece to coordinates $(X, Y)$, and if so, find the minimum number of operations required.
判断是否可以将棋子移动到坐标 $(X, Y)$。如果可以,求所需的最少操作次数。AI (CI翻译)
You are given $T$ test cases; solve each.
给定 $T$ 个测试用例,请分别求解。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1 \le T \le 2 \times 10^5$$1 \le A < B \le 10^6$$0 \le X, Y \le 10^6$- All input values are integers.
$1 \le T \le 2 \times 10^5$$1 \le A < B \le 10^6$$0 \le X, Y \le 10^6$- 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_TAI (CI翻译)
The $i$-th $(1 \le i \le T)$ test case $\text{case}_i$ is given in the following format:
第 $i$ 个($1 \le i \le T$)测试用例 $\text{case}_i$ 按以下格式给出:AI (CI翻译)
A B X Y
A B X YAI (CI翻译)
Output
输出格式
AI (CI翻译)Output the answers for the test cases in order, separated by newlines.
按顺序输出各测试用例的答案,每个答案占一行。AI (CI翻译)
For each test case, if it is possible to move the piece to coordinates $(X, Y)$, output the minimum number of operations required; otherwise, output $-1$.
对于每个测试用例,如果可以将棋子移动到坐标 $(X, Y)$,输出所需的最少操作次数;否则输出 $-1$。AI (CI翻译)
样例
4
1 2 1 0
4 6 3 5
459 2026 0 0
19 2026 523 459459
3
-1
0
2670
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。