Problem list
Log in
#icpc00161 · ICPC NWERC 2014

Around the Track

Diamond I 5.0 s 2048 MB

In order to compare race tracks, we wish to compute their lengths. A racetrack is strictly two-dimensional (no elevation). It is described by two simple polygons, where one is completely contained inside the other. The track is the region between these two polygons. We define the length of the track as the absolute minimum distance that one needs to travel in order to complete a lap. This could involve traveling on the very edge of the track and arbitrarily sharp cornering (see Figure ).

Input

The input consists of:

  • one line with one integer $n$ ($3 \leq n \leq 50$), the number of vertices of the inner polygon;
  • $n$ lines, the $i$th of which contains two integers $x_i$ and $y_i$ ($ -5,000 \leq x_i, y_i \leq 5,000$): the coordinates of the $i$th vertex of the inner polygon;
  • one line with one integer $m$ ($3 \leq m \leq 50$), the number of vertices of the outer polygon;
  • $m$ lines, the $i$th of which contains two integers $x_i$ and $y_i$ ($ -5,000 \leq x_i, y_i \leq 5,000$): the coordinates of the $i$th vertex of the outer polygon.

For both polygons, the vertices are given in counterclockwise order. The borders of the two polygons do not intersect or touch each other.

Output

Output one line with one floating point number: the length of the race track. Your answer should have an absolute or relative error of at most $10^{-6}$.

Example 1

Input
3
1 1
2 1
1 2
3
0 0
4 0
0 4
Output
3.41421356237309

Example 2

Input
5
1 1
5 1
5 5
3 3
1 5
4
0 0
6 0
6 6
0 6
Output
16

Example 3

Input
5
1 1
5 1
5 5
3 3
1 5
5
0 0
6 0
6 6
3 4
0 6
Output
16.4721359549996
Source
ICPC NWERC 2014
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code