diff --git a/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/1.png b/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/1.png new file mode 100644 index 000000000..d5e911ca0 Binary files /dev/null and b/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/1.png differ diff --git a/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/2.jpg b/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/2.jpg new file mode 100644 index 000000000..0e4c1d663 Binary files /dev/null and b/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/2.jpg differ diff --git a/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/3.jpg b/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/3.jpg new file mode 100644 index 000000000..1471160aa Binary files /dev/null and b/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/3.jpg differ diff --git a/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/README.md b/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/README.md index 3d5a5f8d1..d1c874d66 100755 --- a/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/README.md +++ b/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/README.md @@ -1,28 +1,60 @@ # [3025.Find the Number of Ways to Place People I][title] -> [!WARNING|style:flat] -> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm) - ## Description +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. + +**Example 1:** -**Example 1:** +![1](./1.png) ``` -Input: a = "11", b = "1" -Output: "100" +Input: points = [[1,1],[2,2],[3,3]] + +Output: 0 + +Explanation: + +There is no way to choose A and B so A is on the upper left side of B. ``` -## 题意 -> ... +**Example 2:** -## 题解 +![2](./2.jpg) -### 思路1 -> ... -Find the Number of Ways to Place People I -```go ``` +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 middle one is the pair (points[2], points[1]), same as the left one it is a valid pair. +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. +``` + +**Example 3:** + +![3](./3.jpg) + +``` +Input: points = [[3,1],[1,3],[1,1]] + +Output: 2 + +Explanation: + +The left one is the pair (points[2], points[0]), where points[2] is on the upper left side of points[0] and there are no other points on the line they form. Note that it is a valid state when the two points form a line. +The middle one is the pair (points[1], points[2]), it is a valid pair same as the left one. +The right one is the pair (points[1], points[0]), it is not a valid pair as points[2] is on the border of the rectangle. +``` ## 结语 diff --git a/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/Solution.go b/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/Solution.go index d115ccf5e..de6caffe5 100644 --- a/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/Solution.go +++ b/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/Solution.go @@ -1,5 +1,31 @@ package Solution -func Solution(x bool) bool { - return x +func Solution(points [][]int) int { + ans := 0 + l := len(points) + for i := 0; i < l; i++ { + for j := 0; j < l; j++ { + // 检查他俩是否ok + if i == j || !(points[i][0] <= points[j][0] && points[i][1] >= points[j][1]) { + // 不在左上角 + continue + } + k := 0 + for ; k < l; k++ { + if k == i || k == j { + continue + } + x := points[k][0] <= points[j][0] && points[k][0] >= points[i][0] + y := points[k][1] >= points[j][1] && points[k][1] <= points[i][1] + if x && y { + break + } + } + if k == l { + ans++ + } + + } + } + return ans } diff --git a/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/Solution_test.go b/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/Solution_test.go index 14ff50eb4..22b2f7883 100644 --- a/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/Solution_test.go +++ b/leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/Solution_test.go @@ -10,12 +10,12 @@ func TestSolution(t *testing.T) { // 测试用例 cases := []struct { name string - inputs bool - expect bool + inputs [][]int + expect int }{ - {"TestCase", true, true}, - {"TestCase", true, true}, - {"TestCase", false, false}, + {"TestCase1", [][]int{{1, 1}, {2, 2}, {3, 3}}, 0}, + {"TestCase2", [][]int{{6, 2}, {4, 4}, {2, 6}}, 2}, + {"TestCase3", [][]int{{3, 1}, {1, 3}, {1, 1}}, 2}, } // 开始测试 @@ -30,10 +30,10 @@ func TestSolution(t *testing.T) { } } -// 压力测试 +// 压力测试 func BenchmarkSolution(b *testing.B) { } -// 使用案列 +// 使用案列 func ExampleSolution() { }