#P4534. [CTSC2004] 最优切割

[CTSC2004] 最优切割

Description

The HURRICANE team needs to cut out a part from within a template.

Both the template and the part are given convex polygons, and the position of the part inside the template is fixed.

For the part, for any two non-adjacent edges, the intersection point of the extensions of their supporting lines lies outside the template.

Due to factory constraints, each cut must follow the straight line containing some edge of the part, splitting the template into two pieces. Keep the piece that contains the part and continue cutting.

The cost of each cut is the length of the cut mark on the template. You need to compute the minimum total cost required to cut out the part.

Input Format

The first line contains a positive integer nn, the number of vertices of the template.

The next nn lines each contain two real numbers x,yx, y, giving the coordinates of the template’s vertices listed in counterclockwise order.

The (n+2)(n+2)-th line contains a positive integer mm, the number of vertices of the part.

The next mm lines each contain two real numbers x,yx, y, giving the coordinates of the part’s vertices listed in counterclockwise order.

Output Format

Output a single integer, which is the minimum total cost rounded to the nearest integer.

4
0 0
3 0
3 3
0 3
4
1 1
2 1
2 2
1 2
8
4
0 0
3 0
3 3
0 3
4
0 0
2 0
2 3
0 3
3

Hint

For 100%100\% of the testdata, it is guaranteed that 3n,m20003 \le n, m \le 2000 and x,y109|x|, |y| \le 10^9.

Translated by ChatGPT 5