From 614434de14d09b16a550ae30b2898a13456b828e Mon Sep 17 00:00:00 2001 From: MH Hung Date: Wed, 3 Sep 2025 11:03:55 +0800 Subject: [PATCH] [#3027] note(numberOfPairs): add README of Description --- .../README.md | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 problems/3027-find-the-number-of-ways-to-place-people-ii/README.md diff --git a/problems/3027-find-the-number-of-ways-to-place-people-ii/README.md b/problems/3027-find-the-number-of-ways-to-place-people-ii/README.md new file mode 100644 index 0000000..d0096f3 --- /dev/null +++ b/problems/3027-find-the-number-of-ways-to-place-people-ii/README.md @@ -0,0 +1,68 @@ +# [3027] Find The Number Of Ways To Place People II + +## 題目資訊 +- **難度**: Hard +- **標籤**: Array, Math, Geometry, Enumeration +- **題目連結**: [LeetCode](https://leetcode.com/problems/find-the-number-of-ways-to-place-people-ii/) +- **練習日期**: 2025-09-03 + +## 題目描述 + +You are given a 2D array `points` of size `n x 2` representing integer coordinates of some points on a 2D-plane, where `points[i] = [xi, yi]`. + +We define the **right** direction as positive x-axis **(increasing x-coordinate)** and the **left** direction as negative x-axis **(decreasing x-coordinate)**. Similarly, we define the **up** direction as positive y-axis **(increasing y-coordinate)** and the **down** direction as negative y-axis **(decreasing y-coordinate)** + +You have to place `n` people, including Alice and Bob, at these points such that there is **exactly one** person at every point. Alice wants to be alone with Bob, so Alice will build a rectangular fence with Alice's position as the **upper left corner** and Bob's position as the **lower right corner** of the fence (**Note** that the fence **might not** enclose any area, i.e. it can be a line). If any person other than Alice and Bob is either **inside** the fence or on the fence, Alice will be sad. + +Return the number of *pairs of points* where you can place Alice and Bob, such that Alice *does not* become sad on building the fence. + +**Note** that Alice can only build a fence with Alice's position as the upper left corner, and Bob's position as the lower right corner. For example, Alice cannot build either of the fences in the picture below with four corners `(1, 1)`, `(1, 3)`, `(3, 1)`, and `(3, 3)`, because: + + - With Alice at `(3, 3)` and Bob at `(1, 1)`, Alice's position is not the upper left corner and Bob's position is not the lower right corner of the fence. + - With Alice at `(1, 3)` and Bob at `(1, 1)`, Bob's position is not the lower right corner of the fence. + + +## 解題思路 + +### 初步分析 +此題同[#3025](../3025-find-the-number-of-ways-to-place-people-i/README.md) + +### 解法概述 +此題同[#3025](../3025-find-the-number-of-ways-to-place-people-i/README.md) + +## 測試案例 + +### 範例輸入輸出 +``` +Input: points = [[6,2],[4,4],[2,6]] +Output: 2 +Explanation: +There are two ways to place Alice and Bob such that Alice will not be sad: +- Place Alice at (4, 4) and Bob at (6, 2). +- Place Alice at (2, 6) and Bob at (4, 4). +You cannot place Alice at (2, 6) and Bob at (6, 2) because the person at (4, 4) will be inside the fence. +``` + +### 邊界情況 +- 2 <= n <= 1000 +- points[i].length == 2 +- -10^9 <= points[i][0], points[i][1] <= 10^9 +- All points[i] are distinct. + +## 學習筆記 + +### 今天學到什麼? +- 跟 [#3025]一樣, 但多了更多描述, 可能英文要再加強(?) +- 多了更大的邊界條件, 寫unit test 需要考慮更多覆蓋率 + +### 遇到的困難 +- 無 + +### 改善方向 +- 無 + +### 相關題目 +- [#223](https://leetcode.com/problems/rectangle-area/) Rectangle Area + +--- +**總結**: 這題的核心概念是...,適合練習...技巧。