Skip to content

Commit 0b7992d

Browse files
LetMeFly666Copilot
andauthored
update: 添加问题“3027.人员站位的方案数II”的代码和题解 (#1114)
* 3027: WA.cpp (#1112) input: [[1,1],[2,2],[3,3]] should: 0 output: 3 * 3027: WA.cpp (#1112) - 好吧,minY可以是10^{-9} input: [[2,5],[128653,-2370425]] should: 1 output: 0 * 3027: AC.cpp (#1112) - 然后就通过了 cpp - AC,46.07%,39.27% * feat: newSolution auto header (#1113) - half * 3027: AC.py+go | CE.java (#1112) - 思路是某日(9.3)中午小憩时想的 py - AC,36.15%,60.81% go - AC,49.06%,38.26% 9。3站方队? * 3027: CE.java (#1112) * 3027: AC.java | WA.rust (#1112) java - AC,70.03%,83.93% * 3027: AC.rust (#1112) rust - AC,36.20%,7.97% * feat: newSolution auto header (#1112)(#1113) - dbg+foundReason * feat: newSolution auto header (#1112)(#1113) - finish 等下次再“回归”一下再试试吧 * update: 添加问题“3027.人员站位的方案数II”的代码和题解 (#1114) Signed-off-by: LetMeFly666 <[email protected]> * words: en(jp) today (#1112) * feat: newSolution auto header (#1112)(#1113) - clean up * fix: a maybe-won't-happened IndexError: list index out of range Co-authored-by: Copilot <[email protected]> --------- Signed-off-by: LetMeFly666 <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 41271f6 commit 0b7992d

12 files changed

+533
-4
lines changed

.vscode/settings.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,17 @@
9494
"__locale": "cpp",
9595
"ios": "cpp",
9696
"__config": "cpp",
97-
"__bit_reference": "cpp"
97+
"__bit_reference": "cpp",
98+
"any": "cpp",
99+
"barrier": "cpp",
100+
"latch": "cpp",
101+
"numbers": "cpp",
102+
"semaphore": "cpp",
103+
"variant": "cpp",
104+
"__node_handle": "cpp",
105+
"__verbose_abort": "cpp",
106+
"execution": "cpp",
107+
"print": "cpp"
98108
},
99109
"editor.mouseWheelZoom": true,
100110
"workbench.tree.enableStickyScroll": true,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-09-05 09:55:20
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-09-05 10:05:44
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
int numberOfPairs(vector<vector<int>>& points) {
14+
sort(points.begin(), points.end(), [](const vector<int>& a, const vector<int>& b) {
15+
return a[0] == b[0] ? a[1] > b[1] : a[0] < b[0];
16+
});
17+
int ans = 0;
18+
for (int i = 0; i < points.size(); i++) {
19+
int mxY = -1000000001;
20+
for (int j = i + 1; j < points.size(); j++) {
21+
if (points[j][1] > mxY && points[j][1] <= points[i][1]) {
22+
ans++;
23+
mxY = points[j][1];
24+
}
25+
}
26+
}
27+
return ans;
28+
}
29+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-09-05 09:55:20
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-09-05 10:40:12
6+
*/
7+
package main
8+
9+
import "sort"
10+
11+
func numberOfPairs(points [][]int) (ans int) {
12+
sort.Slice(points, func(i int, j int) bool {
13+
if points[i][0] == points[j][0] {
14+
return points[i][1] > points[j][1]
15+
}
16+
return points[i][0] < points[j][0]
17+
})
18+
for i := range points {
19+
mxY := -1000000001
20+
for j := i + 1; j < len(points); j++ {
21+
if points[j][1] > mxY && points[j][1] <= points[i][1] {
22+
mxY = points[j][1]
23+
ans++
24+
}
25+
}
26+
}
27+
return
28+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-09-05 09:55:20
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-09-05 10:44:46
6+
*/
7+
import java.util.Arrays;
8+
9+
class Solution {
10+
public int numberOfPairs(int[][] points) {
11+
Arrays.sort(points, (a, b) -> a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]);
12+
int ans = 0;
13+
for (int i = 0; i < points.length; i++) {
14+
int mxY = -1000000001;
15+
for (int j = i + 1; j < points.length; j++) {
16+
if (points[j][1] > mxY && points[j][1] <= points[i][1]) {
17+
mxY = points[j][1];
18+
ans++;
19+
}
20+
}
21+
}
22+
return ans;
23+
}
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-09-05 09:55:20
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-09-05 10:35:32
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def numberOfPairs(self, points: List[List[int]]) -> int:
11+
points.sort(key=lambda x: (x[0], -x[1]))
12+
ans = 0
13+
for i in range(len(points)):
14+
mxY = -1000000001
15+
for j in range(i + 1, len(points)):
16+
if mxY < points[j][1] <= points[i][1]:
17+
mxY = points[j][1]
18+
ans += 1
19+
return ans
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-09-05 09:55:20
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-09-05 10:49:59
6+
*/
7+
impl Solution {
8+
pub fn number_of_pairs(mut points: Vec<Vec<i32>>) -> i32 { // 想原地sort points的话记得在points前面加上mut
9+
points.sort_by(|a, b| {
10+
if a[0] == b[0] {
11+
b[1].cmp(&a[1])
12+
} else {
13+
a[0].cmp(&b[0])
14+
}
15+
});
16+
let mut ans: i32 = 0;
17+
for i in 0..points.len() {
18+
let mut mx_y: i32 = -1000000001;
19+
for j in (i+1)..points.len() {
20+
if points[j][1] > mx_y && points[j][1] <= points[i][1] {
21+
mx_y = points[j][1];
22+
ans += 1;
23+
}
24+
}
25+
}
26+
ans
27+
}
28+
}

Codes/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
* @LastEditTime: 2025-08-31 19:14:48
66
*/
77
pub struct Solution;
8-
include!("3516-find-closest-person.rs"); // 这个fileName是会被脚本替换掉的
8+
include!("3027-find-the-number-of-ways-to-place-people-ii.rs"); // 这个fileName是会被脚本替换掉的

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@
922922
|3019.按键变更的次数|简单|<a href="https://leetcode.cn/problems/number-of-changing-keys/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/01/07/LeetCode%203019.%E6%8C%89%E9%94%AE%E5%8F%98%E6%9B%B4%E7%9A%84%E6%AC%A1%E6%95%B0/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/144983704" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/number-of-changing-keys/solutions/3040949/letmefly-3019an-jian-bian-geng-de-ci-shu-pgzx/" target="_blank">LeetCode题解</a>|
923923
|3024.三角形类型|简单|<a href="https://leetcode.cn/problems/type-of-triangle/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/05/19/LeetCode%203024.%E4%B8%89%E8%A7%92%E5%BD%A2%E7%B1%BB%E5%9E%8B/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/148061722" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/type-of-triangle/solutions/3680826/letmefly-3024san-jiao-xing-lei-xing-shou-q46h/" target="_blank">LeetCode题解</a>|
924924
|3025.人员站位的方案数I|中等|<a href="https://leetcode.cn/problems/find-the-number-of-ways-to-place-people-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/09/02/LeetCode%203025.%E4%BA%BA%E5%91%98%E7%AB%99%E4%BD%8D%E7%9A%84%E6%96%B9%E6%A1%88%E6%95%B0I/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/151119511" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-the-number-of-ways-to-place-people-i/solutions/3770378/letmefly-3025ren-yuan-zhan-wei-de-fang-a-02tk/" target="_blank">LeetCode题解</a>|
925+
|3027.人员站位的方案数II|困难|<a href="https://leetcode.cn/problems/find-the-number-of-ways-to-place-people-ii/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/09/05/LeetCode%203027.%E4%BA%BA%E5%91%98%E7%AB%99%E4%BD%8D%E7%9A%84%E6%96%B9%E6%A1%88%E6%95%B0II/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/151220862" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-the-number-of-ways-to-place-people-ii/solutions/3772911/letmefly-3027ren-yuan-zhan-wei-de-fang-a-03g4/" target="_blank">LeetCode题解</a>|
925926
|3033.修改矩阵|简单|<a href="https://leetcode.cn/problems/modify-the-matrix/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/07/05/LeetCode%203033.%E4%BF%AE%E6%94%B9%E7%9F%A9%E9%98%B5/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/140219034" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/modify-the-matrix/solutions/2832430/letmefly-3033xiu-gai-ju-zhen-yuan-di-xiu-e0cy/" target="_blank">LeetCode题解</a>|
926927
|3038.相同分数的最大操作数目I|简单|<a href="https://leetcode.cn/problems/maximum-number-of-operations-with-the-same-score-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/06/07/LeetCode%203038.%E7%9B%B8%E5%90%8C%E5%88%86%E6%95%B0%E7%9A%84%E6%9C%80%E5%A4%A7%E6%93%8D%E4%BD%9C%E6%95%B0%E7%9B%AEI/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/139535702" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/maximum-number-of-operations-with-the-same-score-i/solutions/2804245/letmefly-3038xiang-tong-fen-shu-de-zui-d-dkj7/" target="_blank">LeetCode题解</a>|
927928
|3046.分割数组|简单|<a href="https://leetcode.cn/problems/split-the-array/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/12/28/LeetCode%203046.%E5%88%86%E5%89%B2%E6%95%B0%E7%BB%84/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/144789679" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/split-the-array/solutions/3032725/letmefly-3046fen-ge-shu-zu-ji-shu-by-tis-33vv/" target="_blank">LeetCode题解</a>|

0 commit comments

Comments
 (0)