A13880 | Four Points
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given four different integer points $p_1$ , $p_2$ , $p_3$ and $p_4$ on $\mathit{XY}$ grid.
In one step you can choose one of the points $p_i$ and move it in one of four directions by one. In other words, if you have chosen point $p_i = (x, y)$ you can move it to $(x, y + 1)$ , $(x, y - 1)$ , $(x + 1, y)$ or $(x - 1, y)$ .
Your goal to move points in such a way that they will form a square with sides parallel to $\mathit{OX}$ and $\mathit{OY}$ axes (a square with side $0$ is allowed).
What is the minimum number of steps you need to make such a square?
In one step you can choose one of the points $p_i$ and move it in one of four directions by one. In other words, if you have chosen point $p_i = (x, y)$ you can move it to $(x, y + 1)$ , $(x, y - 1)$ , $(x + 1, y)$ or $(x - 1, y)$ .
Your goal to move points in such a way that they will form a square with sides parallel to $\mathit{OX}$ and $\mathit{OY}$ axes (a square with side $0$ is allowed).
What is the minimum number of steps you need to make such a square?
输入格式
The first line contains a single integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases.
Each test case consists of four lines. Each line contains two integers $x$ and $y$ ( $0 \le x, y \le 10^9$ ) — coordinates of one of the points $p_i = (x, y)$ .
All points are different in one test case.
Each test case consists of four lines. Each line contains two integers $x$ and $y$ ( $0 \le x, y \le 10^9$ ) — coordinates of one of the points $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 = 8$ .In the second test case, one of the optimal solutions is shown below:
 The answer is $3 + 1 + 0 + 3 = 7$ .In the third test case, one of the optimal solutions is shown below:
 The answer is $1 + 1 + 2 + 1 = 5$ .
 Each point was moved two times, so the answer $2 + 2 + 2 + 2 = 8$ .In the second test case, one of the optimal solutions is shown below:
 The answer is $3 + 1 + 0 + 3 = 7$ .In the third test case, one of the optimal solutions is shown below:
 The answer is $1 + 1 + 2 + 1 = 5$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted