#abc286h. Ex - Don't Swim

Ex - Don't Swim

Score : 600600 points

问题描述

在一个二维平面上,存在一个有 NN 个顶点的凸多边形 CC,以及两个点 S=(sx,sy)S=(s_x, s_y)T=(tx,ty)T=(t_x,t_y)。多边形 CC 的顶点按逆时针顺序依次为 (x1,y1),(x2,y2),,(xN,yN)(x_1,y_1),(x_2,y_2),\ldots,(x_N,y_N)。保证 SSTT 都在多边形外部。

求从点 SS 到点 TT 的最短路径长度,要求该路径除了经过多边形 CC 的边界外,不能进入其内部。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

On a two-dimensional plane, there is a convex polygon CC with NN vertices, and points S=(sx,sy)S=(s_x, s_y) and T=(tx,ty)T=(t_x,t_y). The vertices of CC are (x1,y1),(x2,y2),(x_1,y_1),(x_2,y_2),\ldots, and (xN,yN)(x_N,y_N) in counterclockwise order. It is guaranteed that SS and TT are outside the polygon.

Find the shortest distance that needs to be traveled to get from point SS to point TT without entering the interior of CC except for its circumference.

Constraints

  • 3N1053\leq N \leq 10^5
  • xi,yi,sx,sy,tx,ty109|x_i|,|y_i|,|s_x|,|s_y|,|t_x|,|t_y|\leq 10^9
  • (x1,y1),(x2,y2),(x_1,y_1),(x_2,y_2),\ldots, and (xN,yN)(x_N,y_N) form a convex polygon in counterclockwise order.
  • No three points of CC are colinear.
  • SS and TT are outside CC and not on the circumference of CC.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

x1x_1 y1y_1

x2x_2 y2y_2

\vdots

xNx_N yNy_N

sxs_x sys_y

txt_x tyt_y

Output

Print the answer.

Your output is considered correct if the absolute or relative error from the true value is at most 10610^{-6}.

Sample Input 1

4
1 1
3 1
3 3
1 3
0 2
5 2

Sample Output 1

5.65028153987288474496

One way to achieve the shortest distance is shown in the following figure.

image

If you travel as (0,2)(1,3)(3,3)(5,2)(0,2) \to (1,3) \to(3,3)\to(5,2), the length of the path from point SS to point TT is 5.650281...5.650281.... We can prove that it is the minimum. Note that you may enter the circumference of CC.

Note that your output is considered correct if the absolute or relative error is at most 10610^{-6}. For example, output like 5.650287 is also considered correct.

Sample Input 2

3
0 0
2 0
1 10
3 7
10 3

Sample Output 2

8.06225774829854965279

update @ 2024/3/10 11:59:03