3454. Separate Squares II Hard
1/**
2 * [3454] Separate Squares II
3 *
4 * You are given a 2D integer array squares. Each squares[i] = [xi, yi, li] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis.
5 * Find the minimum y-coordinate value of a horizontal line such that the total area covered by squares above the line equals the total area covered by squares below the line.
6 * Answers within 10^-5 of the actual answer will be accepted.
7 * Note: Squares may overlap. Overlapping areas should be counted only once in this version.
8 *
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">squares = [[0,0,1],[2,2,1]]</span>
12 * Output: <span class="example-io">1.00000</span>
13 * Explanation:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2025/01/15/4065example1drawio.png" style="width: 269px; height: 203px;" />
15 * Any horizontal line between y = 1 and y = 2 results in an equal split, with 1 square unit above and 1 square unit below. The minimum y-value is 1.
16 * </div>
17 * <strong class="example">Example 2:
18 * <div class="example-block">
19 * Input: <span class="example-io">squares = [[0,0,2],[1,1,1]]</span>
20 * Output: <span class="example-io">1.00000</span>
21 * Explanation:
22 * <img alt="" src="https://assets.leetcode.com/uploads/2025/01/15/4065example2drawio.png" style="width: 269px; height: 203px;" />
23 * Since the blue square overlaps with the red square, it will not be counted again. Thus, the line y = 1 splits the squares into two equal parts.
24 * </div>
25 *
26 * Constraints:
27 *
28 * 1 <= squares.length <= 5 * 10^4
29 * squares[i] = [xi, yi, li]
30 * squares[i].length == 3
31 * 0 <= xi, yi <= 10^9
32 * 1 <= li <= 10^9
33 * The total area of all the squares will not exceed 10^15.
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/separate-squares-ii/
39// discuss: https://leetcode.com/problems/separate-squares-ii/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn separate_squares(squares: Vec<Vec<i32>>) -> f64 {
45 0f64
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_3454() {
57 }
58}
59Back
© 2026 bowen.ge All Rights Reserved.