Files
coding-practice/problems/3025-find-the-number-of-ways-to-place-people-i/README.md

70 lines
2.1 KiB
Markdown
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.

# [3025] Find The Number Of Ways To Place People I
## 題目資訊
- **難度**: Medium
- **標籤**: Array, Math, Geometry, Sorting, Enumeration
- **題目連結**: [LeetCode](https://leetcode.com/problems/find-the-number-of-ways-to-place-people-i/)
- **練習日期**: 2025-09-02
## 題目描述
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]`.
Count the number of pairs of points `(A, B)`, where
- `A` is on **the upper** left side of `B`, and
- there are no other points in the rectangle (or line) they make (**including the border**).
Return the count.
## 解題思路
### 初步分析
- 核心概念
幾何關係判斷 + 區域內點的檢測
- 關鍵限制條件
1. A必須在B的左上方, A.x <= B.x, A.y >= B.y
2. 矩形區域內(包含邊界)不能有其他點
- 預期時間/空間複雜度?
### 解法概述
**解法**:
- 思路:
- 遍歷所有點對 (A, B)
- 檢查每個pair形成的矩形, 裡面跟邊界會不會包含其他點
- 時間複雜度O(N^3)
- 空間複雜度O(1)
## 測試案例
### 範例輸入輸出
```
Input: points = [[6,2],[4,4],[2,6]]
Output: 2
Explanation:
- The left one is the pair (points[1], points[0]), where points[1] is on the upper left side of points[0] and the rectangle is empty.
- The left one is the pair (points[1], points[0]), where points[1] is on the upper left side of points[0] and the rectangle is empty.
- The right one is the pair (points[2], points[0]), where points[2] is on the upper left side of points[0], but points[1] is inside the rectangle so it's not a valid pair.
```
### 邊界情況
- `2 <= n <= 50`
- `points[i].length == 2`
- `0 <= points[i][0], points[i][1] <= 50`
- All `points[i]` are distinct.
## 學習筆記
### 今天學到什麼?
- 二維空間判斷點大小
### 遇到的困難
-
### 改善方向
-
### 相關題目
- [#223](https://leetcode.com/problems/rectangle-area/) Rectangle Area
---
**總結**: 這題的核心概念是...,適合練習...技巧。