Aerial Archeology
Time limit5sMemory limit512 MB
Given several simple polygons that may overlap, find the maximum number of polygons whose interiors a single straight line can pass through.
- Level
Medium7 of 10
- Topics
- Geometry, Brute force, Math
- Solved
- No attempts yet
Problem
Andrew has a summer job with a team of aerial archeologists. The team studies the underground remains of prehistoric cultures with nuclear imaging spectroscopy. Today Andrew plans the route of a helicopter that carries the spectrometer over an area of archeological interest in the nearby lowlands. The spectrometer is sensitive and easy to damage, so the helicopter has to fly at constant speed along a perfectly straight line to keep the measurement noise low.
Several prehistoric settlements lie buried under the surface of the lowlands. Other methods already fixed their positions and boundaries, and all of those boundaries are drawn on one map that Andrew can use. The flight should pass over as many settlements as possible, so Andrew needs the straight line on the map that meets the largest number of settlements drawn there.
The settlement shapes are complicated and the settlements overlap, often chaotically, so it is not obvious where to draw the line.
Input
The input describes the shapes and the positions of the settlements on the map. Each settlement is a simple polygon: no two of its non-adjacent boundary segments touch or intersect each other. Different polygons may overlap.
The input holds several test cases and ends at the end of the file. Each case starts with a line containing one positive integer , the number of polygons on the map. The descriptions of the polygons follow. Each description starts with a line containing one integer (), the number of vertices of the polygon. Each of the next lines contains two integers and separated by a space, the coordinates of one vertex. The vertices are listed in clockwise order along the polygon boundary. All coordinates are integers with absolute value at most . The total number of vertices of all polygons in one test case is at most .
Output
For each test case, print one line with a single integer , the maximum number of polygons on the map that one straight line can intersect. Only intersections of the line with the interior of a polygon count. A line that touches a polygon along its boundary but passes through no point of its interior does not intersect that polygon.