CF1455E.Four Points

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given four different integer points p1p_1, p2p_2, p3p_3 and p4p_4 on XY\mathit{XY} grid.

In one step you can choose one of the points pip_i and move it in one of four directions by one. In other words, if you have chosen point pi=(x,y)p_i = (x, y) you can move it to (x,y+1)(x, y + 1), (x,y−1)(x, y - 1), (x+1,y)(x + 1, y) or (x−1,y)(x - 1, y).

Your goal to move points in such a way that they will form a square with sides parallel to OX\mathit{OX} and OY\mathit{OY} axes (a square with side 00 is allowed).

What is the minimum number of steps you need to make such a square?

给你 XY\mathit{XY} 平面上四个互不相同的整数点 p1p_1、p2p_2、p3p_3 和 p4p_4。

每一步中,你可以任选其中一个点 pip_i,并将其沿四个方向之一移动一个单位。换言之,若你选择了点 pi=(x,y)p_i = (x, y),则可将其移动至 (x,y+1)(x, y + 1)、(x,y−1)(x, y - 1)、(x+1,y)(x + 1, y) 或 (x−1,y)(x - 1, y)。

你的目标是通过移动这些点,使它们构成一个边与 OX\mathit{OX} 轴和 OY\mathit{OY} 轴平行的正方形(允许边长为 00 的退化正方形)。

实现该目标所需的最少步数是多少?

输入格式

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

Each test case consists of four lines. Each line contains two integers xx and yy (0≤x,y≤1090 \le x, y \le 10^9) — coordinates of one of the points pi=(x,y)p_i = (x, y).

All points are different in one test case.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例由四行组成。每行包含两个整数 xx 和 yy(0≤x,y≤1090 \le x, y \le 10^9)—— 其中一个点 pi=(x,y)p_i = (x, y) 的坐标。

在一个测试用例中,所有点互不相同。

输出格式

For each test case, print the single integer — the minimum number of steps to make a square.

对于每个测试用例,输出一个整数——使其成为正方形所需的最少步数。

输入输出样例

  • 输入#1

    3
    0 2
    4 2
    2 0
    2 4
    1 0
    2 0
    4 0
    6 0
    1 6
    2 2
    2 5
    4 1

    输出#1

    8
    7
    5

说明/提示

In the first test case, one of the optimal solutions is shown below:

Each point was moved two times, so the answer 2+2+2+2=82 + 2 + 2 + 2 = 8.

In the second test case, one of the optimal solutions is shown below:

The answer is 3+1+0+3=73 + 1 + 0 + 3 = 7.

In the third test case, one of the optimal solutions is shown below:

The answer is 1+1+2+1=51 + 1 + 2 + 1 = 5.

在第一个测试用例中,其中一个最优解如下所示:

每个点均被移动了两次,因此答案为 2+2+2+2=82 + 2 + 2 + 2 = 8。

在第二个测试用例中,其中一个最优解如下所示:

答案为 3+1+0+3=73 + 1 + 0 + 3 = 7。

在第三个测试用例中,其中一个最优解如下所示:

答案为 1+1+2+1=51 + 1 + 2 + 1 = 5。

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

首页