Around the Track
Time limit2sMemory limit256 MB
Find the shortest closed route that stays between two nested polygons and winds once around the inner one.
- Level
Hard8 of 10
- Topics
- Geometry, Shortest path, Graph
- Solved
- No attempts yet
Problem
To compare race tracks you need their lengths. A track is flat, with no elevation. It is described by two simple polygons, one of which lies completely inside the other. The track is the region between the two polygons, and both boundaries belong to the track.
The length of the track is the shortest distance you have to travel to complete one lap, that is, the length of the shortest closed route that stays inside the track and goes around the inner polygon once. Such a route may run along the very edge of the track, and it may turn arbitrarily sharply at a corner.
Input
The input consists of:
- one line with one integer , the number of vertices of the inner polygon ();
- lines, the th of which contains two integers and , the coordinates of the th vertex of the inner polygon ();
- one line with one integer , the number of vertices of the outer polygon ();
- lines, the th of which contains two integers and , the coordinates of the th vertex of the outer polygon ().
All coordinates are integers. For both polygons the vertices are given in counterclockwise order, and the boundaries of the two polygons neither intersect nor touch each other.
Output
Print the length of the track on one line, rounded to exactly six digits after the decimal point. Print all six digits even when the length is an integer.