Crow
Time limit3sMemory limit256 MB
Sum the shortest path lengths between consecutive query points that stay above the ground and outside a polygonal mountain.
- Level
Hard8 of 10
- Topics
- Geometry, Shortest path, Graph
- Solved
- No attempts yet
Problem
A crow lives on the two dimensional plane. Today it flew around all day again, looking for food and for anything shiny.
The part of the plane with is ground, so the crow cannot go there. There is also one mountain, and the crow cannot go inside it either. The mountain is described by vertices through . The values are given in increasing order, every satisfies , and . Joining through in order and then joining back to gives the boundary of the mountain. The crow may travel along the edges of the mountain, but it cannot enter the interior.
The crow made moves today. It started at , went to next, and so on until it visited and ended the day. The crow is clever, so each move from to took a shortest path that passes through neither the interior of the ground nor the interior of the mountain. Write a program that computes the total distance the crow travelled today.
Input
The first line contains ().
The -th of the next lines contains and (, ) separated by one space. holds for every with , and .
The next line contains ().
The -th of the next lines contains and (, ) separated by one space. No lies inside the mountain. It may lie on the boundary.
Output
Print the total distance the crow travelled, rounded to six digits after the decimal point, on one line. Always print all six digits.
Hint
The terrain of the first example is shown below. Green is the mountain and brown is the ground. The crow can move through the light blue area and along the edges of the mountain and the ground.

The next two pictures show the two moves of the crow. The first move has length and the second has length , so the two together are about .

