QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 256 MB 总分: 100 可 Hack ✓

#11535. 旅行商问题

统计

有 $N$ 座城市,编号从 $1$ 到 $N$,第 $i$ 座城市的坐标为 $(x_i, y_i)$。

Busy Beaver 想要从城市 $1$ 出发,访问每一座城市恰好一次,最后回到城市 $1$。

从城市 $i$ 前往城市 $j$ 需要 $|x_i - x_j + y_i - y_j|$ 秒。请计算 Busy Beaver 完成行程所需的最少秒数。

输入格式

第一行包含一个整数 $T$ ($1 \leq T \leq 10^4$),表示测试用例的数量。

每个测试用例的第一行包含一个整数 $N$ ($2 \leq N \leq 2 \cdot 10^5$),表示城市的数量。

接下来 $N$ 行中的第 $i$ 行包含两个整数 $x_i$ 和 $y_i$ ($-10^9 \leq x_i, y_i \leq 10^9$),表示第 $i$ 座城市的坐标。

所有测试用例的 $N$ 之和不超过 $2 \cdot 10^5$。

输出格式

对于每个测试用例,输出一个整数,表示 Busy Beaver 完成行程所需的最少秒数。

样例

输入格式 1

3
5
0 0
-2 0
1 2
-1 3
0 1
3
0 0
1 4
3 4
2
-1 9
8 -4

输出格式 1

10
14
8

说明

在第一个测试用例中,我们可以采取路径 $1 \xrightarrow{3\,\text{seconds}} 3 \xrightarrow{1\,\text{second}} 4 \xrightarrow{1\,\text{second}} 5 \xrightarrow{3\,\text{seconds}} 2 \xrightarrow{2\,\text{seconds}} 1$,总耗时为 $3+1+1+3+2=10$ 秒。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.