1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-04 23:11:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/分割正方形 I [separate-squares-i].html
2025-02-22 16:46:22 +08:00

58 lines
2.5 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个二维整数数组 <code>squares</code>&nbsp;,其中&nbsp;<code>squares[i] = [x<sub>i</sub>, y<sub>i</sub>, l<sub>i</sub>]</code> 表示一个与 x 轴平行的正方形的左下角坐标和正方形的边长。</p>
<p>找到一个<strong>最小的</strong> y 坐标,它对应一条水平线,该线需要满足它以上正方形的总面积 <strong>等于</strong> 该线以下正方形的总面积。</p>
<p>答案如果与实际答案的误差在 <code>10<sup>-5</sup></code> 以内,将视为正确答案。</p>
<p><strong>注意</strong>:正方形&nbsp;<strong>可能会&nbsp;</strong>重叠。重叠区域应该被&nbsp;<strong>多次计数&nbsp;</strong></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">squares = [[0,0,1],[2,2,1]]</span></p>
<p><strong>输出:</strong> <span class="example-io">1.00000</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://pic.leetcode.cn/1739609465-UaFzhk-4062example1drawio.png" style="width: 378px; height: 352px;" /></p>
<p>任何在 <code>y = 1</code><code>y = 2</code> 之间的水平线都会有 1 平方单位的面积在其上方1 平方单位的面积在其下方。最小的 y 坐标是 1。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">squares = [[0,0,2],[1,1,1]]</span></p>
<p><strong>输出:</strong> <span class="example-io">1.16667</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://pic.leetcode.cn/1739609527-TWqefZ-4062example2drawio.png" style="width: 378px; height: 352px;" /></p>
<p>面积如下:</p>
<ul>
<li>线下的面积:<code>7/6 * 2 (红色) + 1/6 (蓝色) = 15/6 = 2.5</code></li>
<li>线上的面积:<code>5/6 * 2 (红色) + 5/6 (蓝色) = 15/6 = 2.5</code></li>
</ul>
<p>由于线以上和线以下的面积相等,输出为 <code>7/6 = 1.16667</code></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= squares.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>squares[i] = [x<sub>i</sub>, y<sub>i</sub>, l<sub>i</sub>]</code></li>
<li><code>squares[i].length == 3</code></li>
<li><code>0 &lt;= x<sub>i</sub>, y<sub>i</sub> &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= l<sub>i</sub> &lt;= 10<sup>9</sup></code></li>
<li>所有正方形的总面积不超过 <code>10<sup>12</sup></code></li>
</ul>