#P9819. [ICPC2020 Shanghai R] Wowoear

    ID: 9138 远端评测题 7000ms 1024MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>计算几何2020上海Special JudgeO2优化线段相交ICPC

[ICPC2020 Shanghai R] Wowoear

题目描述

Wowo is a solo adventurer who completed many dangerous journeys on his own foot in forests, deserts and even glaciers. The Shanghai ICPC (Shanghai Invitational Contest on Programmable Cheating) committee invited Wowo as a tester of their new running trial.

The trial can be described as a 2D simple polyline (p1,,pn)(p_1,\ldots, p_n). In other words, the trial consists of n1n-1 line segments (p1,p2),,(pn1,pn)(p_1, p_2),\ldots, (p_{n-1}, p_n). The line segments do not intersect with each other except that two consecutive line segments (pi,pi+1)(p_i, p_{i+1}) and (pi+1,pi+2)(p_{i+1}, p_{i+2}) intersect at the point pi+1p_{i+1}. Any two consecutive segments have different directions. The committee wants Wowo to run from p1p_1 to pnp_n along the line segments (p1,p2),,(pn1,pn)(p_1,p_2),\ldots, (p_{n-1}, p_n) in order.

However, Wowo has a smart device that can hack the committee's system for an interval of time. Wowo is able to choose 22 points a,ba, b on the trial and run directly from aa to bb along the line segment (a,b)(a, b). Each of these aa and bb can be some pip_i (1in1\le i\le n) and can be some point on some line segment (pi,pi+1)(p_i, p_{i+1}) (1i<n1\le i<n) as well. Before reaching aa and after reaching bb, Wowo has to run along the original trial. Wowo does not want to be caught cheating, so he decided that the line segment (a,b)(a, b) should not intersect or touch any line segment of the trial at any point other than aa and bb. Help Wowo to choose aa and bb wisely and output the shortest distance Wowo need to run from p1p_1 to pnp_n using his smart cheating device.

输入格式

The first line includes a single integer nn indicating the number of points on the running trial (2n2002\le n\le 200).

The i+1i+1-th line (1in1\le i\le n) contains two integers xx and yy separated by a single space indicating the coordinates of pip_i (1000x,y1000-1000\le x, y\le 1000).

It is guaranteed that the line segments do not intersect with each other except that two consecutive line segments (pi,pi+1)(p_i, p_{i+1}) and (pi+1,pi+2)(p_{i+1}, p_{i+2}) intersect at the point pi+1p_{i+1}. In other words, $(p_i, p_{i+1})\cap (p_{j}, p_{j+1})=\left\{\begin{array}{cc}\emptyset & i\neq j-1\\ \{p_{j}\} & i = j-1\end{array}\right.$ holds for any integers i,ji, j satisfying 1i<j<n1\le i< j<n. Here (s,t)(s, t) represents all points on the line segment from ss to tt including ss and tt.

It is guaranteed that each line segment has nonzero length. In other words, pipi+1p_i\neq p_{i+1} for any integer i[1,n)i\in [1, n).

It is guaranteed that adjacent line segments are not collinear. In other words, for any integer i[1,n2]i\in [1,n-2] and any real number λ\lambda, pipi+1p_i - p_{i+1} is not\textbf{not} equal to λ(pi+1pi+2)\lambda(p_{i+1}-p_{i+2}).

输出格式

Output the shortest distance Wowo needs to run. Your answer will be considered correct if its absolute or relative error does not exceed 10610^{-6}.

题目大意

题目描述

Wowo 是一位单人冒险家,他曾独自一人在森林、沙漠甚至冰川中完成过许多危险的旅程。ICPC(上海市可编程作弊邀请赛)组委会邀请 Wowo 作为新的跑步测试员。

该试验可描述为二维简单折线 (p1,,pn)(p_1,\ldots, p_n)。换句话说,试验由 n1n-1 条线段 (p1,p2),,(pn1,pn)(p_1, p_2),\ldots, (p_{n-1}, p_n) 组成。除了两个连续的线段 (pi,pi+1)(p_i, p_{i+1})(pi+1,pi+2)(p_{i+1}, p_{i+2}) 相交于点 pi+1p_{i+1} 外,其他线段互不相交。任何两条连续的线段都有不同的方向。委员会希望 Wowo 从 p1p_1pnp_n 依次沿着线段 (p1,p2),,(pn1,pn)(p_1,p_2),\ldots, (p_{n-1}, p_n) 运行。

然而,Wowo 拥有一个智能设备,可以在一段时间内侵入委员会的系统。Wowo 能够在试验中选择 22a,ba, b ,并沿着线段 (a,b)(a, b) 直接从 aa 跑到 bb 。其中每个 aabb 都可以是某个 pip_i1in1\le i\le n)。(1in1\le i\le n) ,也可以是线段 (pi,pi+1)(p_i, p_{i+1}) 上的某一点。(1in1\le i \le n)上的某一点。在到达 aa 之前和 bb 之后,Wowo 必须沿着原来的试验路线运行。沃沃不想被发现作弊,所以他决定线段 (a,b)(a, b) 不能与试验中的任何线段相交,也不能接触到 aabb 以外的任何点。请帮助 Wowo 明智地选择 aabb ,并利用他的智能作弊装置输出 Wowo 需要从 p1p_1 跑到 pnp_n 的最短距离

输入格式

第一行包含一个整数 nn ,表示运行试验中的点数( 2n2002\le n\le 200 )。

i+1i+11in1\le i\le n)行包含两个整数 xxyy,中间用一个空格隔开,表示 pip_i1000x,y1000-1000\le x, y\le 1000)的坐标。

除了两条连续的线段 (pi,pi+1)(p_i, p_{i+1})(pi+1,pi+2)(p_{i+1}, p_{i+2}) 相交于点 pi+1p_{i+1} 之外,其他线段保证互不相交。换句话说,对于满足 1i<j<n1 \le i\lt j \lt n 的任何整数 i,ji, j,$(p_i, p_{i+1})\cap (p_{j}, p_{j+1})=\left\{\begin{array}{cc}\emptyset & i\neq j-1\\ \{p_{j}\} & i = j-1\end{array}\right.$ 都成立。这里的 (s,t)(s, t) 代表从 sstt 的线段上的所有点,包括 sstt。 可以保证每条线段的长度都不为零。换句话说,pipi+1p_i\neq p_{i+1} 满足任意整数 i[1,n)i\in [1, n)

保证相邻线段不相交。换句话说,对于任意整数 i[1,n2]i\in [1,n-2] 和任意实数 λ\lambdapipi+1p_i - p_{i+1}等于λ(pi+1pi+2)\lambda(p_{i+1}-p_{i+2})

输出格式

输出 Wowo 需要运行的最短距离。如果答案的绝对误差或相对误差不超过 10610^{-6},则认为答案正确。
Translation by nightwatch_ryan

5
0 0
1 10
2 0
3 10
4 0
22.099751242242