BoxUnion
SRM 237 · 2005-04-06 · by legakis
Problem Statement
Given a list of two-dimensional rectangles, compute the area of their union. For example, the union of the three rectangles shown in the figure below:

cover an area of 35 units.
The list of rectangles will be given as a
{ "1 3 5 6",
"3 1 7 5",
"4 4 9 7" }
Constraints
- rectangles will contain between 1 and 3 elements, inclusive.
- Each element of rectangles will be formatted as described in the problem statement.
- For each rectangle, the left coordinate will be less than the right coordinate and the bottom coordinate will be less than the top coordinate.
- All coordinates will be between 0 and 20000, inclusive.
{ "200 300 203 304" }
Returns: 12
A single rectangle with area 12.
{ "0 0 10 10",
"20 20 30 30" }
Returns: 200
Two disjoint rectangles, each of area 100.
{ "0 500 20000 501",
"500 0 501 20000" }
Returns: 39999
These two rectangles intersect at a single point.
{ "4 6 18 24",
"7 2 12 19",
"0 0 100 100" }
Returns: 10000
The third rectangle completely overlaps the first two.
{ "1 3 5 6",
"3 1 7 5",
"4 4 9 7" }
Returns: 35
This is the example from the problem statement.
Submissions are judged against all 17 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class BoxUnion with a public method int area(vector<string> rectangles) · 17 test cases · 2 s / 256 MB per case