Maps
Time limit1sMemory limit128 MB
Given up to a million arbitrarily rotated rectangles, find the number of edges of their common intersection polygon.
- Level
Hard8 of 10
- Topics
- Geometry, Implementation, Math, Sorting
- Solved
- No attempts yet
Problem
Bajtazar owns a large collection of maps of Poland. Some are road maps, others are tourist maps, and so on. Every map has the shape of a rectangle, and a map may be rotated arbitrarily. Each map carries useful information about various places across the country.
Standing at a particular point, Bajtazar would like that point to appear on every one of his maps at once. He therefore wonders about the shape of the region that all the maps have in common. This common region is always a convex polygon, and your only task is to determine how many edges it has.
Task
- Read the list of rectangles describing the area covered by each map.
- Print the number of edges of the polygon formed by the common region of these rectangles.
Input
The first line contains one integer (), the number of rectangles.
Each of the next lines describes one rectangle with eight integers separated by single spaces: the coordinate pairs of its four vertices listed in counter-clockwise order. Every coordinate satisfies .
You may assume that the area of the common region of all the rectangles is strictly greater than .
Output
Print a single integer: the number of edges of the polygon formed by the common region of the rectangles.
Hint
