CF1428A.Box is Pull

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x1,y1)(x_1,y_1) to the point (x2,y2)(x_2,y_2).

He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 11 unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by 11 unit.

For example, if the box is at the point (1,2)(1,2) and Wabbit is standing at the point (2,2)(2,2), he can pull the box right by 11 unit, with the box ending up at the point (2,2)(2,2) and Wabbit ending at the point (3,2)(3,2).

Also, Wabbit can move 11 unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly 11 unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.

Wabbit can start at any point. It takes 11 second to travel 11 unit right, left, up, or down, regardless of whether he pulls the box while moving.

Determine the minimum amount of time he needs to move the box from (x1,y1)(x_1,y_1) to (x2,y2)(x_2,y_2). Note that the point where Wabbit ends up at does not matter.

兔子沃比特正试图在坐标平面上将一个装有动物园其余动物食物的箱子从点 (x1,y1)(x_1,y_1) 移动到点 (x2,y2)(x_2,y_2)。

他有一根绳子,可用于拉动箱子。他仅当自己恰好位于箱子正左、正右、正上或正下方(即与箱子在某一坐标轴方向上距离恰好为 11 单位)时,才能拉动箱子。他将箱子拉向自己所站位置,然后自己再沿相同方向移动 11 单位以让开。

例如,若箱子位于点 (1,2)(1,2),而沃比特站在点 (2,2)(2,2),则他可向右拉动箱子 11 单位:箱子最终到达点 (2,2)(2,2),而沃比特最终到达点 (3,2)(3,2)。

此外,沃比特也可在不拉动箱子的情况下,向右、向左、向上或向下移动 11 单位。此时,他无需与箱子保持恰好 11 单位的距离。若他想再次拉动箱子,则必须重新回到箱子邻接的位置(即上下左右四个方向之一)。同时,沃比特不能移动到箱子当前所在的位置。

沃比特可从任意点出发。无论是否在移动过程中拉动箱子,他向右、向左、向上或向下移动 11 单位均需耗时 11 秒。

请确定将箱子从 (x1,y1)(x_1,y_1) 移动到 (x2,y2)(x_2,y_2) 所需的最短时间。注意:沃比特最终所处的位置无关紧要。

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤1000)(1 \leq t \leq 1000): the number of test cases. The description of the test cases follows.

Each of the next tt lines contains four space-separated integers x1,y1,x2,y2x_1, y_1, x_2, y_2 (1≤x1,y1,x2,y2≤109)(1 \leq x_1, y_1, x_2, y_2 \leq 10^9), describing the next test case.

每个测试包含多个测试用例。第一行包含一个整数 tt (1≤t≤1000)(1 \leq t \leq 1000):测试用例的数量。随后是各测试用例的描述。

接下来的 tt 行中,每行包含四个以空格分隔的整数 x1,y1,x2,y2x_1, y_1, x_2, y_2 (1≤x1,y1,x2,y2≤109)(1 \leq x_1, y_1, x_2, y_2 \leq 10^9),用于描述下一个测试用例。

输出格式

For each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from (x1,y1)(x_1,y_1) to (x2,y2)(x_2,y_2).

对于每个测试用例,输出一个整数:Wabbit 将箱子从 (x1,y1)(x_1,y_1) 运送到 (x2,y2)(x_2,y_2) 所需的最少时间(单位:秒)。

输入输出样例

  • 输入#1

    2
    1 2 2 2
    1 1 2 2

    输出#1

    1
    4

说明/提示

In the first test case, the starting and the ending points of the box are (1,2)(1,2) and (2,2)(2,2) respectively. This is the same as the picture in the statement. Wabbit needs only 11 second to move as shown in the picture in the statement.

In the second test case, Wabbit can start at the point (2,1)(2,1). He pulls the box to (2,1)(2,1) while moving to (3,1)(3,1). He then moves to (3,2)(3,2) and then to (2,2)(2,2) without pulling the box. Then, he pulls the box to (2,2)(2,2) while moving to (2,3)(2,3). It takes 44 seconds.

在第一个测试用例中,箱子的起点和终点分别为 (1,2)(1,2) 和 (2,2)(2,2),这与题目描述中的图片一致。Wabbit 仅需 11 秒即可完成如题目描述图片中所示的移动。

在第二个测试用例中,Wabbit 可从点 (2,1)(2,1) 开始。他一边将箱子拉至 (2,1)(2,1),一边自己移动到 (3,1)(3,1);接着,他在不拉动箱子的情况下依次移动到 (3,2)(3,2) 和 (2,2)(2,2);然后,他一边将箱子拉至 (2,2)(2,2),一边自己移动到 (2,3)(2,3)。整个过程耗时 44 秒。

输入解题思路,AI测评打分。不知道怎么写?

首页