CF1806A.Walking Master
入门
通过率:0%
时间限制:1.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
YunQian is standing on an infinite plane with the Cartesian coordinate system on it. In one move, she can move to the diagonally adjacent point on the top right or the adjacent point on the left.
That is, if she is standing on point (x,y), she can either move to point (x+1,y+1) or point (x−1,y).
YunQian initially stands at point (a,b) and wants to move to point (c,d). Find the minimum number of moves she needs to make or declare that it is impossible.
云倩站在一个带有笛卡尔坐标系的无限平面上。在一次移动中,她可以移动到右上方的对角相邻点,或左侧的相邻点。
也就是说,如果她当前位于点 (x,y),则她可以移动到点 (x+1,y+1) 或点 (x−1,y)。
云倩初始位置为点 (a,b),目标是到达点 (c,d)。请找出她所需的最少移动次数;若无法到达,请说明不可能。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of test cases follows.
The first line and only line of each test case contain four integers a, b, c, d (−108≤a,b,c,d≤108).
第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。随后是各测试用例的描述。
每个测试用例仅有一行,包含四个整数 a、b、c、d(−108≤a,b,c,d≤108)。
输出格式
For each test case, if it is possible to move from point (a,b) to point (c,d), output the minimum number of moves. Otherwise, output −1.
对于每个测试用例,如果能够从点 (a,b) 移动到点 (c,d),则输出最少移动步数;否则输出 −1。
输入输出样例
输入#1
6 -1 0 -1 2 0 0 4 5 -2 -1 1 1 -3 2 -3 2 2 -1 -1 -1 1 1 0 2
输出#1
4 6 -1 0 3 3
说明/提示
In the first test case, one possible way using 4 moves is (−1,0)→(0,1)→(−1,1)→(0,2)→(−1,2). It can be proven that it is impossible to move from point (−1,0) to point (−1,2) in less than 4 moves.
在第一个测试用例中,一种使用 4 步的可行路径为 (−1,0)→(0,1)→(−1,1)→(0,2)→(−1,2)。可以证明:从点 (−1,0) 移动到点 (−1,2) 所需的步数不可能少于 4 步。
输入解题思路,AI测评打分。不知道怎么写?