Polygon and Lines
Time limit0.5sMemory limit128 MB
For each line crossing a convex polygon, find the closest polygon vertex to the line and print the distance.
- Level
Medium7 of 10
- Topics
- Geometry, Binary search
- Solved
- No attempts yet
Problem
Gustav likes to solve geometry problems. While browsing geometry problems on the internet he ran into one he could not solve on his own, so help him solve the following problem.
You are given one convex polygon and several lines that cross it. For each line, find the vertex of the polygon closest to that line and compute the distance between the line and that vertex.
A line crosses the polygon if it has at least one point in common with the interior of the polygon.
Input
The first line contains the number of vertices of the polygon ().
Each of the next lines holds the coordinates of one vertex of the convex polygon: two integers whose absolute value is smaller than . The vertices are given in clockwise order.
The next line contains the number of lines ().
Each of the next lines holds three integers , , that describe the line . Here , and and are never both . Every given line crosses the polygon.
Output
Print lines. Line holds the distance between line and the closest vertex of the polygon, rounded to three decimal places.