Union of Rectangle
Xem dạng PDF
Gửi bài giải
Điểm:
1,00 (OI)
Giới hạn thời gian:
1.5s
Giới hạn bộ nhớ:
256M
Input:
stdin
Output:
stdout
Nguồn bài:
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
Rectangles lie on a plane with their sides along the axes, overlapping freely. Find the area they cover between them, counting overlapped ground once.
Adding the areas up double counts every overlap, and subtracting the pairwise overlaps then removes the triple ones twice over. Cutting the plane along every edge instead leaves a grid of small rectangles, each either wholly covered or wholly clear, and those can simply be added up.
Input
The rectangle count, then all left edges and all right edges on a line each. Then the count again, then all bottom edges and all top edges on a line each.
Output
The area covered.
Sample test cases
Input
2
0 1
2 3
2
0 1
2 3
Expected output
7
Input
3
0 1 0
3 2 3
3
0 0 2
1 3 3
Expected output
7
Bình luận