#P9819. [ICPC 2020 Shanghai R] Wowoear

    ID: 9101 Type: RemoteJudge 7000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>计算几何2020上海Special JudgeO2优化线段相交ICPC

[ICPC 2020 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}.

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