AT_abc459_g.Golf 2
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given integers A,B,X,Y.
A piece is placed on a two-dimensional plane. Initially, the piece is at coordinates (0,0).
You can perform the following operation zero or more times:
- 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
Determine whether it is possible to move the piece to coordinates (X,Y), and if so, find the minimum number of operations required.
You are given T test cases; solve each.
给你整数 A,B,X,Y。
一个棋子被放置在二维平面上,初始时位于坐标 (0,0) 处。
你可以执行以下操作零次或多次:
- 设棋子当前坐标为 (x,y),将其移动至满足以下任一条件的坐标 (x′,y′):
- ∣x−x′∣=A 且 ∣y−y′∣=B
- ∣x−x′∣=B 且 ∣y−y′∣=A
判断是否能将棋子移动到坐标 (X,Y);若可以,求出所需的最少操作次数。
你将得到 T 组测试用例,请对每组分别求解。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
The i-th (1≤i≤T) test case casei is given in the following format:
A B X Y
输入从标准输入中按以下格式给出:
T
case1
case2
⋮
caseT
第 i 个 (1≤i≤T) 测试用例 casei 按以下格式给出:
A B X Y
输出格式
Output the answers for the test cases in order, separated by newlines.
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。
输入输出样例
输入#1
4 1 2 1 0 4 6 3 5 459 2026 0 0 19 2026 523 459459
输出#1
3 -1 0 2670
说明/提示
Sample 1 Explanation:
Consider the first test case.
By moving the piece from (0,0) to (1,2), then to (−1,1), then to (1,0) in order, the piece can be moved to coordinates (1,0) in three operations.
It is impossible to move the piece to coordinates (1,0) in fewer than three operations, so output 3 on the first line.
Constraints
- 1≤T≤2×105
- 1≤A<B≤106
- 0≤X,Y≤106
- All input values are integers.
样例 1 解释:
考虑第一个测试用例。
按顺序将棋子从 (0,0) 移动到 (1,2),再移动到 (−1,1),最后移动到 (1,0),共需三步操作,即可将棋子移至坐标 (1,0)。
无法在少于三步操作内将棋子移至坐标 (1,0),因此第一行输出 3。
约束条件
- 1≤T≤2×105
- 1≤A<B≤106
- 0≤X,Y≤106
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?