#BS0000412. Chia diện tích hình vuông II (Separate Squares II)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chia diện tích hình vuông II (Separate Squares II)
Separate Squares II
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
There are axis-aligned squares in the coordinate plane. Square has lower-left corner and side length . Squares may intersect. The covered region is the union of all squares, so any overlap contributes area only once. Find the smallest height at which the horizontal line divides this union into two regions of equal area. Points on the line itself contribute zero area.
Input
The first line contains integer . Each of the following lines contains three integers for square .
Output
Print the minimum required height as a real number. The absolute error must not exceed .
Subtasks
- Subtask 1 (20 points): ; ; for every ; .
- Subtask 2 (30 points): ; ; for every ; .
- Subtask 3 (50 points): ; ; for every ; .
Examples
Input
2
0 0 1
2 2 1
Output
1.00000
Explanation
The two disjoint squares each have area 1. At height 1 the first is below the line and the second above it. Heights in balance the areas, but smaller heights leave less than 1 below. The minimum is 1, illustrated on the left. 
Input
2
0 0 2
1 1 1
Output
1.00000
Explanation
The smaller square is inside the larger one, so the union area is 4 rather than 5. At height 1 the region below is 2 units wide and 1 unit high, giving area 2; the region above also has area 2. Lower heights leave less than 2 below. The answer is 1.