P24978 [AtCoder] [ARC042B] Takahashi the Ant
普及
题目描述

Problem Description

Takahashi the Ant is on a convex polygonal board. He walks straight in the direction he is facing, but we do not know which direction that is. Takahashi will fall off the board if he reaches the edge. Given the position of Takahashi and the vertices of the convex polygon that forms the board, find the shortest distance Takahashi will walk before falling off the board. All positions are given in 2D coordinates.

Input Format

The input is given from the standard input in the following format:

$ x $ $ y $ $ N $ $ x_1 $ $ y_1 $ $ x_2 $ $ y_2 $ : $ x_N $ $ y_N $

  • The first line contains the coordinates of Takahashi's position, represented by integers $x,\ y\ (-100\ ≦\ x\ ≦\ 100,\ -100\ ≦\ y\ ≦\ 100)$ separated by spaces.
  • The second line contains the number of vertices of the polygon, represented by an integer $N\ (3\ ≦\ N\ ≦\ 10)$.
  • The next $ N $ lines contain the coordinates of the vertices of the board, represented by integers $x_i\ y_i\ (-100\ ≦\ x_i\ ≦\ 100,\ -100\ ≦\ y_i\ ≦\ 100)$ separated by spaces. The vertices are given in counterclockwise order.
  • Takahashi's position is guaranteed to be inside the board, not on the edge.
  • The board is guaranteed to be a convex polygon.

Output Format

Output the shortest distance Takahashi will walk before falling off the board in one line. The output will be accepted if the absolute or relative error is at most $ 10^{−6} $.

Sample Input and Output

Sample Input #1

0 0
4
100 100
-100 100
-100 -100
100 -100

Sample Output #1

100

Sample Input #2

10 10
3
0 100
-100 -100
100 -100

Sample Output #2

31.3049516850

Sample Input #3

34 6
7
-43 -65
-23 -99
54 -68
65 92
16 83
-18 43
-39 2

Sample Output #3

25.0284205314

Notes/Hints

Sample Explanation 1

Walking perpendicular to any of the sides will make Takahashi walk $ 100 $ units before falling off the board. [MATH0]

Sample Explanation 3

![](https://arc041.contest.atcoder.jp/img/arc/042/adafrrg/B3.png)

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
0 0 4 100 100 -100 100 -100 -100 100 -100
样例输出
100