CF1455E.Four Points

普及/提高-

通过率:0%

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,y1)(x, y - 1) , (x+1,y)(x + 1, y) or (x1,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?

输入格式

The first line contains a single integer tt ( 1t1041 \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 ( 0x,y1090 \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.

输出格式

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 .

首页