Unreal Estate
Time limit10sMemory limit128 MB
Given up to 5000 rectangles with real coordinates, compute the total area their union covers, counting overlaps once, and print it rounded to two decimals.
- Level
Medium7 of 10
- Topics
- Geometry, Sorting, Divide and conquer, Segment tree
- Solved
- No attempts yet
Problem
A dishonest landowner is selling off plots of land. He sells them as large rectangular plots, but many of the plots overlap, so he is really selling the same land multiple times! It is not real estate, it is unreal estate!
Given a list of the (possibly overlapping) rectangular plots the landowner has sold, determine the total actual area of land they cover. Overlapping regions are counted only once.
Input
The input contains several test cases. Each test case begins with a line containing a single integer (), the number of plots sold. Each of the next lines describes one rectangular plot as four real numbers:
x1 y1 x2 y2
where is the southwest (bottom-left) corner and is the northeast (top-right) corner, with and . Every plot has an area of at least .
The input ends with a line containing a single .
Output
For each test case, output a single real number: the total actual area covered by all of the rectangular plots. Print this value rounded to exactly two decimal places. Do not print any spaces, and do not print any blank lines between outputs.