CF1806A.Walking Master

普及/提高-

通过率:0%

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)(x,y) , she can either move to point (x+1,y+1)(x+1,y+1) or point (x1,y)(x-1,y) .

YunQian initially stands at point (a,b)(a,b) and wants to move to point (c,d)(c,d) . Find the minimum number of moves she needs to make or declare that it is impossible.

输入格式

The first line contains a single integer tt ( 1t1041\le t\le 10^4 ) — the number of test cases. The description of test cases follows.

The first line and only line of each test case contain four integers aa , bb , cc , dd ( 108a,b,c,d108-10^8\le a,b,c,d\le 10^8 ).

输出格式

For each test case, if it is possible to move from point (a,b)(a,b) to point (c,d)(c,d) , output the minimum number of moves. Otherwise, output 1-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 44 moves is (1,0)(0,1)(1,1)(0,2)(1,2)(-1,0)\to (0,1)\to (-1,1)\to (0,2)\to (-1,2) . It can be proven that it is impossible to move from point (1,0)(-1,0) to point (1,2)(-1,2) in less than 44 moves.

首页