Straight Lines 2
Time limit1sMemory limit128 MB
Given a possibly self-intersecting polygon and several lines, find the squared distance from each line to the polygon and print it as an exact irreducible fraction.
- Level
Medium7 of 10
- Topics
- Geometry, Math, Binary search, Sorting
- Solved
- No attempts yet
Problem
The distance from a line to a polygon is the smallest distance between that line and any point of the polygon. Here the polygon means both its boundary (its edges) and its interior. The polygon does not have to be convex: vertices may repeat and the boundary may cross itself.
Write a program that:
- reads a polygon and several lines from standard input,
- for each line computes the distance from that line to the polygon,
- writes the results to standard output.
Input
The first line contains two integers and (, ), separated by a space: the number of vertices of the polygon and the number of lines to analyze.
Each of the next lines contains two integers and (), the coordinates of the -th vertex. Each pair of consecutive vertices, and also the last vertex together with the first, forms a side of the polygon.
Each of the next lines contains three integers , and (, ), describing the line .
Output
Print lines. The -th line must contain the square of the distance between the -th line and the polygon, written as an irreducible fraction: the numerator, a / sign, then the positive denominator. If the line touches or crosses the polygon the distance is , printed as 0/1.
Hint
