#P6923. [ICPC2016 WF] Polygonal Puzzle

[ICPC2016 WF] Polygonal Puzzle

题目描述

During last year’s ACM ICPC World Finals in Marrakesh, one of the judges bought a pretty wooden puzzle depicting a camel and palm trees (see Figure 1). Unlike traditional jigsaw puzzles, which are usually created by cutting up an existing rectangular picture, all the pieces of this puzzle have been cut and painted separately. As a result, adjacent pieces often do not share common picture elements or colors. Moreover, the resulting picture itself is irregularly shaped. Given these properties, the shape of individual pieces is often the only possible way to tell where each piece should be placed.

Figure 1: The judge’s wooden puzzle.

The judge has been wondering ever since last year whether it is possible to write a program to solve this puzzle. An important part of such a program is a method to evaluate how well two puzzle pieces “match” each other. The better the match, the more likely it is that those pieces are adjacent in the puzzle.

Pieces are modeled as simple polygons. Your task is to find a placement of two given polygons such that their interiors do not overlap but the polygons touch with their boundaries and the length of the common boundary is maximized. For this placement, polygons can be translated and rotated, but not reflected or resized. Figure 2 illustrates the optimal placement for Sample Input 1.

Figure 2: Sample Input 1 and its optimal placement.

输入格式

The input contains the description of two polygons, one after the other. Each polygon description starts with a line containing an integer nn (3n503 \leq n \leq 50) denoting the number of vertices of the polygon. This is followed by nn lines, each containing two integer coordinates xx, yy of a polygon vertex (x,y100|x|, |y| \leq 100). The vertices of each polygon are given in clockwise order, and no three consecutive vertices are collinear.

The input data is chosen so that even if the vertices were moved by a distance of up to 10710^{-7}, the answer would not increase by more than 10410^{-4}.

输出格式

Display the maximum possible length of the common boundary of these polygons when they are optimally placed. Your answer should have an absolute or relative error of less than 10310^{-3}.

题目大意

题意简述

有两个多边形,可以平移旋转(但不能对称、缩放等),求这两个多边形贴在一起但不重合的情况下贴贴部分的最大总长度。

输入格式

第一行一个数字n1n_1,表示第一个多边形是n1n_1边形。

接下来n1n_1行,每行两个数字,表示第一个多边形每个端点的横、纵坐标。

接下来一个数字n2n_2,表示第二个多边形是n2n_2边形。

最后n2n_2行,每行两个数字,表示第二个多边形每个端点的横、纵坐标。

输出格式

一行,最大的贴贴部分长度,绝对误差或相对误差任一小于10310^{-3}即可通过。

数据范围

3n1,n2503 \leq n_1, n_2 \leq 50, 横纵坐标均为整数且绝对值不超过100。

8
0 0
0 10
10 10
15 15
24 6
24 10
30 10
30 0
7
-5 0
-5 10
10 10
15 5
20 10
35 10
35 0

30.142135624

3
1 0
0 30
40 0
3
1 0
0 30
40 0

50

提示

Time limit: 18000 ms, Memory limit: 1048576 kB.

International Collegiate Programming Contest (ACM-ICPC) World Finals 2016