QOJ.ac

QOJ

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

#10539. Mausoleum

Statistics

Geo III 国王的陵墓是一个巨大的直方图形状的石质结构。直方图是一个简单的直角多边形,其边界由两条链组成:一条相对于水平轴单调的上链,以及一条称为基底段的水平线段(见图 E.1)。

图 E.1. 一座陵墓以及 $S$ 和 $T$ 之间的一些路径

据传,陵墓内某处藏有宝藏。著名的寻宝猎人 Metry 已经发现了宝藏的位置 $T$。Metry 的计划是打破陵墓的墙壁,进入内部并取回宝藏。她将从陵墓外的一个特定位置 $S$ 出发。利用她的装备,Metry 只能在一个点上钻孔,该点必须对应陵墓边界上的一个顶点。由于在所有顶点处钻穿墙壁所需的时间相同,因此最小化所花费时间的关键在于找到从 $S$ 到 $T$ 的最短路径。

图 E.1 展示了一座陵墓以及从 $S$ 到 $T$ 的几条可能路径,其中顶点仅被穿过一次。经过顶点 $a$ 的路径总长度为 $11.385165 = 6 + \sqrt{29}$,经过顶点 $b$ 的路径长度为 $10.077687 = \sqrt{20} + \sqrt{13} + 2$,经过顶点 $c$ 的路径长度为 $11.0 = 2 + \sqrt{25} + 4$。其中,最短路径是经过顶点 $b$ 的那条。

给定陵墓的边界以及 $S$ 和 $T$ 的位置,编写一个程序,求出在仅穿过一个顶点的情况下,从 $S$ 到 $T$ 的最短路径长度。

输入格式

程序从标准输入读取数据。输入的第一行包含一个整数 $n$ ($4 \le n \le 100,000$),其中 $n$ 为偶数,表示代表陵墓的直方图的顶点数。第二行包含 $n$ 个整数 $v_1, v_2, \dots, v_n$ ($v_1 = v_n = 0, 0 \le v_i \le 10^6$),它们代表垂直边的 $x$ 坐标和水平边的 $y$ 坐标。当你沿着直方图的上链从基底段的左端遍历到右端时,垂直边和水平边交替出现。每条边的长度至少为 1,且 $x$ 坐标按严格递增顺序给出。最后一行包含四个整数 $s_x, s_y, t_x, t_y$ ($-10^6 \le s_x, s_y \le 2 \times 10^6, 0 < t_x, t_y < 10^6$),其中 $(s_x, s_y)$ 和 $(t_x, t_y)$ 分别对应点 $S$ 和 $T$。注意,$S$ 是直方图外的一点,$T$ 是直方图内的一点,两者均不在边界上。

输出格式

程序向标准输出写入数据。仅打印一行。该行应包含一个实数,即从 $S$ 到 $T$ 的最短路径长度。你的输出 $z$ 应包含整数部分、小数点和小数部分。如果满足 $a - 10^{-3} < z < a + 10^{-3}$(其中 $a$ 为评测答案),则该输出被判定为“正确”。两点 $p = (x_1, y_1)$ 和 $q = (x_2, y_2)$ 之间的欧几里得距离为 $\sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2}$。

样例

输入 1

12
0 5 2 8 5 3 7 6 11 4 13 0
11 8 3 3

输出 1

10.077687

输入 2

8
0 7 2 2 5 7 7 0
-2 4 6 4

输出 2

11.767829

输入 3

4
0 5 8 0
8 6 4 2

输出 3

6.0

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#589Editorial Open集训队作业 解题报告 by 孙梓航Qingyu2026-01-02 22:40:05 Download

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.