|
| 1 | +# [1924. Erect the Fence II](https://leetcode-cn.com/problems/erect-the-fence-ii) |
| 2 | + |
| 3 | +[English Version](/solution/1900-1999/1924.Erect%20the%20Fence%20II/README_EN.md) |
| 4 | + |
| 5 | +## 题目描述 |
| 6 | + |
| 7 | +<!-- 这里写题目描述 --> |
| 8 | + |
| 9 | +<p>You are given a 2D integer array <code>trees</code> where <code>trees[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents the location of the <code>i<sup>th</sup></code> tree in the garden.</p> |
| 10 | + |
| 11 | +<p>You are asked to fence the entire garden using the minimum length of rope possible. The garden is well-fenced only if <strong>all the trees are enclosed</strong> and the rope used <strong>forms a perfect circle</strong>. A tree is considered enclosed if it is inside or on the border of the circle.</p> |
| 12 | + |
| 13 | +<p>More formally, you must form a circle using the rope with a center <code>(x, y)</code> and radius <code>r</code> where all trees lie inside or on the circle and <code>r</code> is <strong>minimum</strong>.</p> |
| 14 | + |
| 15 | +<p>Return <em>the center and radius of the circle as a length 3 array </em><code>[x, y, r]</code><em>.</em> Answers within <code>10<sup>-5</sup></code> of the actual answer will be accepted.</p> |
| 16 | + |
| 17 | +<p> </p> |
| 18 | +<p><strong>Example 1:</strong></p> |
| 19 | + |
| 20 | +<p><strong><img alt="" src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1924.Erect%20the%20Fence%20II/images/trees1.png" style="width: 510px; height: 501px;" /></strong></p> |
| 21 | + |
| 22 | +<pre> |
| 23 | +<strong>Input:</strong> trees = [[1,1],[2,2],[2,0],[2,4],[3,3],[4,2]] |
| 24 | +<strong>Output:</strong> [2.00000,2.00000,2.00000] |
| 25 | +<strong>Explanation:</strong> The fence will have center = (2, 2) and radius = 2 |
| 26 | +</pre> |
| 27 | + |
| 28 | +<p><strong>Example 2:</strong></p> |
| 29 | + |
| 30 | +<p><strong><img alt="" src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1924.Erect%20the%20Fence%20II/images/trees2.png" style="width: 510px; height: 501px;" /></strong></p> |
| 31 | + |
| 32 | +<pre> |
| 33 | +<strong>Input:</strong> trees = [[1,2],[2,2],[4,2]] |
| 34 | +<strong>Output:</strong> [2.50000,2.00000,1.50000] |
| 35 | +<strong>Explanation:</strong> The fence will have center = (2.5, 2) and radius = 1.5 |
| 36 | +</pre> |
| 37 | + |
| 38 | +<p> </p> |
| 39 | +<p><strong>Constraints:</strong></p> |
| 40 | + |
| 41 | +<ul> |
| 42 | + <li><code>1 <= trees.length <= 3000</code></li> |
| 43 | + <li><code>trees[i].length == 2</code></li> |
| 44 | + <li><code>0 <= x<sub>i</sub>, y<sub>i</sub> <= 3000</code></li> |
| 45 | +</ul> |
| 46 | + |
| 47 | + |
| 48 | +## 解法 |
| 49 | + |
| 50 | +<!-- 这里可写通用的实现逻辑 --> |
| 51 | + |
| 52 | +<!-- tabs:start --> |
| 53 | + |
| 54 | +### **Python3** |
| 55 | + |
| 56 | +<!-- 这里可写当前语言的特殊实现逻辑 --> |
| 57 | + |
| 58 | +```python |
| 59 | + |
| 60 | +``` |
| 61 | + |
| 62 | +### **Java** |
| 63 | + |
| 64 | +<!-- 这里可写当前语言的特殊实现逻辑 --> |
| 65 | + |
| 66 | +```java |
| 67 | + |
| 68 | +``` |
| 69 | + |
| 70 | +### **...** |
| 71 | + |
| 72 | +``` |
| 73 | +
|
| 74 | +``` |
| 75 | + |
| 76 | +<!-- tabs:end --> |
0 commit comments