QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#21645. If you are a man, you must score 80 points problem

Statistics

Given two simple polygons, the first with $N$ vertices and the second with $M$ vertices. You are free to rotate or translate these polygons, but they must not intersect except at their boundaries. If a point lies on both the first polygon and the second polygon, it is said to belong to the common part of the boundaries of these two polygons. You wish to maximize the sum of the lengths of the common parts of the boundaries of these two polygons.

Input

The first line contains an integer $N$, representing the number of vertices of the first polygon. The next $N$ lines each contain two coordinates, giving each point of the first polygon in clockwise order. The next line contains an integer $M$, representing the number of vertices of the second polygon. The next $M$ lines each contain two coordinates, giving each point of the second polygon in clockwise order.

The data guarantees that for each polygon, no three points are collinear, and any perturbation of any point by $10^{-7}$ will not affect the answer by more than $10^{-4}$.

Output

Output a single real number representing the answer. The error should not exceed $10^{-3}$.

Constraints

  • For 10% of the data, $N, M \le 3$
  • For 20% of the data, $N, M \le 4$
  • For 40% of the data, $N, M \le 10$
  • For 80% of the data, $N, M \le 25$
  • For 100% of the data, $3 \le N, M \le 50$, $-100 \le x_{ij}, y_{ij} \le 100$

Examples

Input 1

3
40 0
0 0
0 30
3
10 0
0 -40
-10 0

Output 1

50.000000000000

Note

Figure 1. Illustration of the optimal solution for the first sample.

Input 2

24
-90 0
-70 10
-75 -5
-55 5
-60 -10
-40 0
-45 -15
-25 -5
-30 -20
-10 -10
-15 -25
5 -15
0 -30
20 -20
15 -35
35 -25
30 -40
50 -30
45 -45
65 -35
60 -50
80 -40
74 -58
-91 -3
24
-90 0
-70 10
-75 -5
-55 5
-60 -10
-40 0
-45 -15
-25 -5
-30 -20
-10 -10
-15 -25
5 -15
0 -30
20 -20
15 -35
35 -25
30 -40
50 -30
45 -45
65 -35
60 -50
80 -40
74 -58
-91 -3

Output 2

404.081360533396

Input 3

8
0 0
0 5
5 5
5 10
10 10
10 5
50 5
50 0
28
0 0
0 10
5 10
5 5
10 5
10 10
15 10
15 5
20 5
20 10
25 10
25 5
30 5
30 10
35 10
35 5
40 5
40 10
45 10
45 5
50 5
50 10
55 10
55 0
30 0
30 -1
25 -1
25 0

Output 3

40.000000000000

Note

Figure 2. Illustration of the optimal solution for the third sample.

Input 4

50
100 -100
-100 -100
76 50
-37 65
-26 23
-68 27
-73 34
-7 97
25 87
51 98
67 82
84 82
59 -23
97 -71
36 -52
-22 -73
47 -2
45 -2
-10 -29
-38 -89
39 -64
35 -95
8 -94
-2 -81
29 -91
29 -76
21 -82
12 -83
18 -73
-62 -96
-8 -88
-24 -91
-17 -95
5 -99
17 -98
66 -92
60 -66
60 -71
30 -55
84 -71
90 -85
99 -84
91 -23
91 38
72 17
90 -19
67 -29
63 -26
79 53
100 100
50
100 -100
-100 -100
-100 100
-53 79
26 63
29 67
19 90
-17 72
-38 91
23 91
84 99
85 90
71 84
55 30
71 60
66 60
92 66
98 17
99 5
95 -17
91 -24
88 -8
96 -62
73 18
83 12
82 21
76 29
91 29
81 -2
94 8
95 35
64 39
89 -38
29 -10
2 45
2 47
73 -22
52 36
71 97
23 59
-82 84
-82 67
-98 51
-87 25
-97 -7
-34 -73
-27 -68
-23 -26
-65 -37
-50 76

Output 4

2134.700202856237

Note

Figure 3. Illustration of the optimal solution for the fourth sample.

Input 5

49
100 61
73 47
81 53
94 59
34 84
35 71
26 73
-1 84
15 61
30 21
20 26
17 30
14 29
8 32
7 35
2 35
-24 48
-27 37
-22 -3
17 0
8 -23
-5 -14
9 -6
-40 -4
-30 -19
-18 -45
-14 -37
-12 -48
-27 -43
-42 -3
-40 6
-28 20
-38 15
-62 27
-53 5
-89 8
-94 -2
-76 -11
-46 -51
-79 -17
-93 -20
-98 -5
-90 11
-60 31
-11 59
6 58
-6 84
7 95
38 92
50
55 -54
72 -15
47 -20
50 -34
24 -46
28 -8
36 -22
49 -1
12 15
3 -13
13 -33
-3 -35
-19 -12
-1 24
-30 41
-59 -2
-51 34
-38 75
-26 59
-40 46
-13 45
-15 66
-18 95
-2 82
-3 50
7 55
15 41
0 11
27 35
49 24
32 20
51 3
63 32
69 24
63 7
78 27
82 10
68 2
85 -4
70 -44
70 -34
61 -62
37 -80
46 -57
21 -92
30 -64
-4 -62
5 -44
19 -56
50 -44

Output 5

134.956838840254

Note

Figure 4. Illustration of the optimal solution for the fifth sample.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.