luogu#P9819. [ICPC2020 Shanghai R] Wowoear
[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 . 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 .
题目大意
题目描述
Wowo 是一位单人冒险家,他曾独自一人在森林、沙漠甚至冰川中完成过许多危险的旅程。ICPC(上海市可编程作弊邀请赛)组委会邀请 Wowo 作为新的跑步测试员。
该试验可描述为二维简单折线 。换句话说,试验由 条线段 组成。除了两个连续的线段 和 相交于点 外,其他线段互不相交。任何两条连续的线段都有不同的方向。委员会希望 Wowo 从 到 依次沿着线段 运行。
然而,Wowo 拥有一个智能设备,可以在一段时间内侵入委员会的系统。Wowo 能够在试验中选择 点 ,并沿着线段 直接从 跑到 。其中每个 和 都可以是某个 ()。() ,也可以是线段 上的某一点。()上的某一点。在到达 之前和 之后,Wowo 必须沿着原来的试验路线运行。沃沃不想被发现作弊,所以他决定线段 不能与试验中的任何线段相交,也不能接触到 和 以外的任何点。请帮助 Wowo 明智地选择 和 ,并利用他的智能作弊装置输出 Wowo 需要从 跑到 的最短距离
输入格式
第一行包含一个整数 ,表示运行试验中的点数( )。
第 ()行包含两个整数 和 ,中间用一个空格隔开,表示 ()的坐标。
除了两条连续的线段 和 相交于点 之外,其他线段保证互不相交。换句话说,对于满足 的任何整数 ,$(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.$ 都成立。这里的 代表从 到 的线段上的所有点,包括 和 。 可以保证每条线段的长度都不为零。换句话说, 满足任意整数 。
保证相邻线段不相交。换句话说,对于任意整数 和任意实数 , 不等于。
输出格式
输出 Wowo 需要运行的最短距离。如果答案的绝对误差或相对误差不超过 ,则认为答案正确。
Translation by nightwatch_ryan
5
0 0
1 10
2 0
3 10
4 0
22.099751242242