#P9819. [ICPC 2020 Shanghai R] Wowoear
[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 . In other words, the trial consists of line segments . The line segments do not intersect with each other except that two consecutive line segments and intersect at the point . Any two consecutive segments have different directions. The committee wants Wowo to run from to along the line segments 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 points on the trial and run directly from to along the line segment . Each of these and can be some () and can be some point on some line segment () as well. Before reaching and after reaching , Wowo has to run along the original trial. Wowo does not want to be caught cheating, so he decided that the line segment should not intersect or touch any line segment of the trial at any point other than and . Help Wowo to choose and wisely and output the shortest distance Wowo need to run from to using his smart cheating device.
输入格式
The first line includes a single integer indicating the number of points on the running trial ().
The -th line () contains two integers and separated by a single space indicating the coordinates of ().
It is guaranteed that the line segments do not intersect with each other except that two consecutive line segments and intersect at the point . 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 satisfying . Here represents all points on the line segment from to including and .
It is guaranteed that each line segment has nonzero length. In other words, for any integer .
It is guaranteed that adjacent line segments are not collinear. In other words, for any integer and any real number , is equal to .
输出格式
Output the shortest distance Wowo needs to run. Your answer will be considered correct if its absolute or relative error does not exceed .
5
0 0
1 10
2 0
3 10
4 0
22.099751242242