|
| 1 | +# [3025. Find the Number of Ways to Place People I](https://leetcode.com/problems/find-the-number-of-ways-to-place-people-i) |
| 2 | + |
| 3 | +[中文文档](/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/README.md) |
| 4 | + |
| 5 | +## Description |
| 6 | + |
| 7 | +<p>You are given a 2D array <code>points</code> of size <code>n x 2</code> representing integer coordinates of some points on a 2D-plane, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>.</p> |
| 8 | + |
| 9 | +<p>We define the <strong>right</strong> direction as positive x-axis (<strong>increasing x-coordinate</strong>) and the <strong>left</strong> direction as negative x-axis (<strong>decreasing x-coordinate</strong>). Similarly, we define the <strong>up</strong> direction as positive y-axis (<strong>increasing y-coordinate</strong>) and the <strong>down</strong> direction as negative y-axis (<strong>decreasing y-coordinate</strong>)</p> |
| 10 | + |
| 11 | +<p>You have to place <code>n</code> people, including Chisato and Takina, at these points such that there is <strong>exactly one</strong> person at every point. Chisato wants to be alone with Takina, so Chisato will build a rectangular fence with Chisato's position as the <strong>upper left corner</strong> and Takina's position as the <strong>lower right corner</strong> of the fence (<strong>Note</strong> that the fence <strong>might not</strong> enclose any area, i.e. it can be a line). If any person other than Chisato and Takina is either <strong>inside</strong> the fence or <strong>on</strong> the fence, Chisato will be sad.</p> |
| 12 | + |
| 13 | +<p>Return <em>the number of <strong>pairs of points</strong> where you can place Chisato and Takina, such that Chisato <strong>does not</strong> become sad on building the fence</em>.</p> |
| 14 | + |
| 15 | +<p><strong>Note</strong> that Chisato can only build a fence with Chisato's position as the upper left corner, and Takina's position as the lower right corner. For example, Chisato cannot build either of the fences in the picture below with four corners <code>(1, 1)</code>, <code>(1, 3)</code>, <code>(3, 1)</code>, and <code>(3, 3)</code>, because:</p> |
| 16 | + |
| 17 | +<ul> |
| 18 | + <li>With Chisato at <code>(3, 3)</code> and Takina at <code>(1, 1)</code>, Chisato's position is not the upper left corner and Takina's position is not the lower right corner of the fence.</li> |
| 19 | + <li>With Chisato at <code>(1, 3)</code> and Takina at <code>(1, 1)</code>, Takina's position is not the lower right corner of the fence.</li> |
| 20 | +</ul> |
| 21 | +<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/images/example0alicebob-1.png" style="width: 750px; height: 308px;padding: 10px; background: #fff; border-radius: .5rem;" /> |
| 22 | +<p> </p> |
| 23 | +<p><strong class="example">Example 1:</strong></p> |
| 24 | +<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/images/example1alicebob.png" style="width: 376px; height: 308px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem;" /> |
| 25 | +<pre> |
| 26 | +<strong>Input:</strong> points = [[1,1],[2,2],[3,3]] |
| 27 | +<strong>Output:</strong> 0 |
| 28 | +<strong>Explanation:</strong> There is no way to place Chisato and Takina such that Chisato can build a fence with Chisato's position as the upper left corner and Takina's position as the lower right corner. Hence we return 0. |
| 29 | +</pre> |
| 30 | + |
| 31 | +<p><strong class="example">Example 2:</strong></p> |
| 32 | +<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/images/example2chisatotakina.png" style="width: 1121px; height: 308px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem;" /> |
| 33 | +<pre> |
| 34 | +<strong>Input:</strong> points = [[6,2],[4,4],[2,6]] |
| 35 | +<strong>Output:</strong> 2 |
| 36 | +<strong>Explanation:</strong> There are two ways to place Chisato and Takina such that Chisato will not be sad: |
| 37 | +- Place Chisato at (4, 4) and Takina at (6, 2). |
| 38 | +- Place Chisato at (2, 6) and Takina at (4, 4). |
| 39 | +You cannot place Chisato at (2, 6) and Takina at (6, 2) because the person at (4, 4) will be inside the fence. |
| 40 | +</pre> |
| 41 | + |
| 42 | +<p><strong class="example">Example 3:</strong></p> |
| 43 | +<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/images/chisatotakinaexample3.png" style="width: 1123px; height: 308px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem;" /> |
| 44 | +<pre> |
| 45 | +<strong>Input:</strong> points = [[3,1],[1,3],[1,1]] |
| 46 | +<strong>Output:</strong> 2 |
| 47 | +<strong>Explanation:</strong> There are two ways to place Chisato and Takina such that Chisato will not be sad: |
| 48 | +- Place Chisato at (1, 1) and Takina at (3, 1). |
| 49 | +- Place Chisato at (1, 3) and Takina at (1, 1). |
| 50 | +You cannot place Chisato at (1, 3) and Takina at (3, 1) because the person at (1, 1) will be on the fence. |
| 51 | +Note that it does not matter if the fence encloses any area, the first and second fences in the image are valid. |
| 52 | +</pre> |
| 53 | + |
| 54 | +<p> </p> |
| 55 | +<p><strong>Constraints:</strong></p> |
| 56 | + |
| 57 | +<ul> |
| 58 | + <li><code>2 <= n <= 50</code></li> |
| 59 | + <li><code>points[i].length == 2</code></li> |
| 60 | + <li><code>0 <= points[i][0], points[i][1] <= 50</code></li> |
| 61 | + <li>All <code>points[i]</code> are distinct.</li> |
| 62 | +</ul> |
| 63 | + |
| 64 | +## Solutions |
| 65 | + |
| 66 | +### Solution 1 |
| 67 | + |
| 68 | +<!-- tabs:start --> |
| 69 | + |
| 70 | +```python |
| 71 | + |
| 72 | +``` |
| 73 | + |
| 74 | +```java |
| 75 | + |
| 76 | +``` |
| 77 | + |
| 78 | +```cpp |
| 79 | + |
| 80 | +``` |
| 81 | + |
| 82 | +```go |
| 83 | + |
| 84 | +``` |
| 85 | + |
| 86 | +<!-- tabs:end --> |
| 87 | + |
| 88 | +<!-- end --> |
0 commit comments