QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 2048 MB Total points: 100

#1290. 接入点

Statistics

一个著名的编程竞赛正在考虑一种安置参赛队伍的新方法。为了比赛,所有 $n$ 支队伍都必须被安置在无限大的体育馆内的某个位置 $(x, y)$。为了方便管理队伍,采用了以下策略:

所有队伍都被分配了一个范围在 $[1, n]$ 内的唯一整数 ID。对于任意两支 ID 分别为 $i$ 和 $j$ 的队伍,若 $i < j$,则它们被安置的位置 $(x_i, y_i)$ 和 $(x_j, y_j)$ 必须满足 $x_i \le x_j$ 且 $y_i \le y_j$。

不幸的是,有人已经为每支队伍分配了(固定的)互联网接入点。接入点很大且只有一个端口,因此不同队伍的接入点位于不同的位置。每支队伍必须通过一根直接的 UTP 电缆连接到其指定的接入点。长度为 $\ell$ 的 UTP 电缆成本为 $\ell^2$。

请找到一种所有队伍的安置方案,使得它们在两个坐标轴上的相对顺序得以保持,并且所需 UTP 电缆的总成本最小。由于裁判不太担心隐私问题,他们允许两支(或多支)队伍被安置在完全相同的位置,或者彼此靠得无限近。参见图 A.1 了解示例。

图 A.1:样例输入 1 的最优安置方案示意图。队伍位置(方块)、接入点(圆圈)以及所需的 UTP 电缆(虚线)。

输入格式

输入包含: 一行一个整数 $n$ ($1 \le n \le 10^5$),表示队伍数量。 $n$ 行,第 $i$ 行包含两个整数 $s_i, t_i$ ($1 \le s_i, t_i \le 10^6$),表示第 $i$ 支队伍的互联网接入点位置。

没有两个接入点位于相同的位置。

输出格式

输出在最优合法布局下,将所有队伍连接到其接入点所需的 UTP 电缆总成本的最小值。

你的答案应具有不超过 $10^{-6}$ 的绝对或相对误差。

样例

输入 1

6
4 1
2 4
3 2
8 3
5 6
2 5

输出 1

22.5

输入 2

6
11 6
23 7
24 11
24 32
27 38
42 42

输出 2

0

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.