#P16127. [ICPC 2018 NAIPC] Cut It Out!

[ICPC 2018 NAIPC] Cut It Out!

题目描述

You are given two convex polygons AA and BB. It is guaranteed that BB is strictly contained inside of AA.

You would like to make a sequence of cuts to cut out BB from AA. To do this, you draw a straight line completely through AA that is incident to one of the edges of BB, which separates AA into two pieces. You cut along this line and discard the piece that doesn’t contain BB. You repeat this until the piece that you have left is exactly BB.

:::align{center} :::

The cost of making a cut is equal to the length of the cut (i.e. the length of the line through the remainder of AA). Given AA and BB, find the minimum cost needed to cut BB out.

输入格式

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. Each test case will begin with a line containing a single integer aa (3a2003 \leq a \leq 200), which is the number of points in polygon AA. Each of the next aa lines will contain two integers xx and yy (106x,y106-10^6 \leq x, y \leq 10^6), which are the vertices of polygon AA, in clockwise order. It is guaranteed that polygon AA will be convex.

The next line will contain a single integer bb (3b2003 \leq b \leq 200), which is the number of points in polygon BB. Each of the next bb lines will contain two integers xx and yy (106<x,y<106-10^6 < x, y < 10^6), which are the vertices of polygon BB, in clockwise order. It is guaranteed that polygon BB will be convex. It is also guaranteed that polygon BB will reside entirely within the interior of polygon AA.

No three points, within a polygon or across polygons, will be collinear.

输出格式

Output a single floating point number, which is the minimum cost to cut BB out of AA. To be considered correct, this number must be within a relative error of 10610^{-6} of the judges’ answer.

4
0 0
0 14
15 14
15 0
4
8 3
4 6
7 10
11 7
40.0000000000
4
-100 -100
-100 100
100 100
100 -100
8
-1 -2
-2 -1
-2 1
-1 2
1 2
2 1
2 -1
1 -2
322.1421356237