#P2288. [HNOI2005] 纸片覆盖

[HNOI2005] 纸片覆盖

Description

Xiaofu, who likes geometry, encountered the following problem: one day he drew nn lines on a white sheet of paper, and then cut out a small mm-gon (simple polygon).

He wants to place this small paper piece on the sheet so that the total length of the lines it covers is maximized. The polygon piece cannot be flipped or rotated; it can only be translated. If some portion of a line happens to coincide with an edge of the polygon, then that segment is considered covered.

Can you help him solve this problem?

Input Format

Read from the file input.txt. The first line contains two numbers nn and mm, where 1n,m101 \leq n, m \leq 10, denoting the number of lines and the number of edges of the polygon, respectively.

Each of the next nn lines describes a line, with 44 real numbers x1,y1,x2,y2x_1, y_1, x_2, y_2, representing a line passing through (x1,y1)\left(x_1, y_1\right) and (x2,y2)\left(x_2, y_2\right).

Each of the next mm lines gives the vertices of the polygon in either clockwise or counterclockwise order, with 22 real numbers x,yx, y, representing the coordinates of a vertex.

Assume all input real numbers are between 10000-10000 and 1000010000, and have no more than 22 decimal places. The input polygon is guaranteed to be non-self-intersecting, and no three consecutive points are collinear.

Output Format

The output file output.txt contains only one number LL, the maximum total length of line segments that the input polygon can cover, accurate to 33 decimal places.

3 5
6 1 2 5
1 2 8 4
4 -1 5 6
1 0
5 -1
4 2
7 3
4 4

11.933

Hint

Translated by ChatGPT 5