Skip to content

Commit 1d8056b

Browse files
committed
update(docs,typo): 添加问题“3025.人员站位的方案数I”的代码和题解+文章Mac发烫 (#1109)
3025: AC.cpp+py+go (#1108) cpp - AC,28.00%,90.00% cpp(rewrite) - AC,26.00%,50.00% py - AC,13.64%,18.18% go - AC,57.14%,42.86% rust和java详见下一个分支吧 git stash push -m "hello from #1108" Codes/lib.rs Codes/*.java Codes/*.rs 保存工作目录和索引状态 On 3025: hello from #1108 Signed-off-by: LetMeFly666 <[email protected]>
1 parent bfb4ac8 commit 1d8056b

14 files changed

+596
-17
lines changed

.commitmsg

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
3025: AC.cpp+py+go (#1108)
2+
3+
cpp - AC,28.00%,90.00%
4+
cpp(rewrite) - AC,26.00%,50.00%
5+
py - AC,13.64%,18.18%
6+
go - AC,57.14%,42.86%
7+
8+
rust和java详见下一个分支吧
9+
git stash push -m "hello from #1108" Codes/lib.rs Codes/*.java Codes/*.rs
10+
保存工作目录和索引状态 On 3025: hello from #1108

Codes/2438-range-product-queries-of-powers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def productQueries(self, n: int, queries: List[List[int]]) -> List[int]:
1515
pows.append(1 << th)
1616
th += 1
1717
n >>= 1
18-
perfix = [1] * (len(pows) + 1)
18+
prefix = [1] * (len(pows) + 1)
1919
for i in range(1, len(pows) + 1):
20-
perfix[i] = perfix[i - 1] * pows[i - 1]
21-
return [perfix[q[1] + 1] // perfix[q[0]] % 1000000007 for q in queries]
20+
prefix[i] = prefix[i - 1] * pows[i - 1]
21+
return [prefix[q[1] + 1] // prefix[q[0]] % 1000000007 for q in queries]
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-09-02 13:08:07
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-09-02 13:45:45
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
private:
13+
inline bool check(vector<vector<int>>& points, int i, int j) { // 易错点3:单独的(i, j)也要check
14+
if (points[i][0] > points[j][0] || points[i][1] < points[j][1]) { // 易错点1:注意这里纵坐标大于等于才合法
15+
return false;
16+
}
17+
return true;
18+
}
19+
inline bool check(vector<vector<int>>& points, int i, int j, int k) {
20+
if (points[i][0] <= points[k][0] && points[k][0] <= points[j][0] && points[i][1] >= points[k][1] && points[k][1] >= points[j][1]) {
21+
return false;
22+
}
23+
return true;
24+
}
25+
public:
26+
int numberOfPairs(vector<vector<int>>& points) {
27+
int ans = 0;
28+
for (int i = 0; i < points.size(); i++) {
29+
for (int j = 0; j < points.size(); j++) {
30+
if (i == j) {
31+
continue;
32+
}
33+
if (!check(points, i, j)) {
34+
continue;
35+
}
36+
bool can = true; // 易错点2:有一个k导致不符就不符
37+
for (int k = 0; k < points.size(); k++) {
38+
if (k == i || k == j) {
39+
continue;
40+
}
41+
if (!check(points, i, j, k)) {
42+
can = false;
43+
break;
44+
}
45+
}
46+
ans += can;
47+
}
48+
}
49+
return ans;
50+
}
51+
};
52+
53+
#if defined(_WIN32) || defined(__APPLE__)
54+
/*
55+
[[1,1],[2,2],[3,3]]
56+
57+
0
58+
*/
59+
/*
60+
[[0,0],[0,3]]
61+
62+
1
63+
*/
64+
/*
65+
[[6,2],[4,4],[2,6]]
66+
67+
(2,1) (1, 0)
68+
69+
2
70+
*/
71+
/*
72+
[[0,0],[0,3]]
73+
74+
1
75+
*/
76+
int main() {
77+
string s;
78+
while (cin >> s) {
79+
vector<vector<int>> v = stringToVectorVector(s);
80+
Solution sol;
81+
cout << sol.numberOfPairs(v) << endl;
82+
}
83+
return 0;
84+
}
85+
#endif
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-09-02 13:08:07
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-09-02 18:53:07
6+
*/
7+
package main
8+
9+
func check2_3025(points [][]int, i, j int) bool {
10+
return points[i][0] <= points[j][0] && points[i][1] >= points[j][1]
11+
}
12+
13+
func check3_3025(points [][]int, i, j, k int) bool {
14+
return !(points[i][0] <= points[k][0] && points[k][0] <= points[j][0] &&
15+
points[i][1] >= points[k][1] && points[k][1] >= points[j][1])
16+
}
17+
18+
func numberOfPairs(points [][]int) (ans int) {
19+
for i := range points {
20+
for j := range points {
21+
if i == j {
22+
continue
23+
}
24+
if !check2_3025(points, i, j) {
25+
continue
26+
}
27+
can := true
28+
for k := range points {
29+
if k == i || k == j {
30+
continue
31+
}
32+
if !check3_3025(points, i, j, k) {
33+
can = false
34+
break
35+
}
36+
}
37+
if can {
38+
ans++
39+
}
40+
}
41+
}
42+
return
43+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-09-02 13:08:07
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-09-02 18:47:49
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def check2(self, i: int, j: int) -> bool:
11+
return self.points[i][0] <= self.points[j][0] and self.points[i][1] >= self.points[j][1]
12+
13+
def check3(self, i: int, j: int, k: int) -> bool:
14+
return not (self.points[i][0] <= self.points[k][0] <= self.points[j][0] and self.points[i][1] >= self.points[k][1] >= self.points[j][1])
15+
16+
def numberOfPairs(self, points: List[List[int]]) -> int:
17+
ans = 0
18+
n = len(points)
19+
self.points = points
20+
for i in range(n):
21+
for j in range(n):
22+
if i == j:
23+
continue
24+
if not self.check2(i, j):
25+
continue
26+
can = True
27+
for k in range(n):
28+
if k == i or k == j:
29+
continue
30+
if not self.check3(i, j, k):
31+
can = False
32+
break
33+
ans += can
34+
return ans
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-09-02 13:08:07
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-09-02 13:51:14
6+
* @Description: rewrite from 0
7+
*/
8+
#if defined(_WIN32) || defined(__APPLE__)
9+
#include "_[1,2]toVector.h"
10+
#endif
11+
12+
class Solution {
13+
private:
14+
inline bool check(vector<vector<int>>& points, int i, int j) {
15+
return i != j && points[i][0] <= points[j][0] && points[i][1] >= points[j][1];
16+
}
17+
18+
inline bool check(vector<vector<int>>& points, int i, int j, int k) {
19+
return !(points[i][0] <= points[k][0] && points[k][0] <= points[j][0]
20+
&& points[i][1] >= points[k][1] && points[k][1] >= points[j][1]);
21+
}
22+
public:
23+
int numberOfPairs(vector<vector<int>>& points) {
24+
int ans = 0;
25+
for (int i = 0; i < points.size(); i++) {
26+
for (int j = 0; j < points.size(); j++) {
27+
if (!check(points, i, j)) {
28+
continue;
29+
}
30+
bool can = true;
31+
for (int k = 0; k < points.size(); k++) {
32+
if (k == i || k == j) {
33+
continue;
34+
}
35+
if (!check(points, i, j, k)) {
36+
can = false;
37+
break;
38+
}
39+
}
40+
ans += can;
41+
}
42+
}
43+
return ans;
44+
}
45+
};
46+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,7 @@
921921
|3011.判断一个数组是否可以变为有序|中等|<a href="https://leetcode.cn/problems/find-if-array-can-be-sorted/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/07/13/LeetCode%203011.%E5%88%A4%E6%96%AD%E4%B8%80%E4%B8%AA%E6%95%B0%E7%BB%84%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E5%8F%98%E4%B8%BA%E6%9C%89%E5%BA%8F/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/140391465" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-if-array-can-be-sorted/solutions/2841665/letmefly-3011pan-duan-yi-ge-shu-zu-shi-f-i9ck/" target="_blank">LeetCode题解</a>|
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>|
924+
|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>|
924925
|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>|
925926
|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>|
926927
|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>|

Solutions/LeetCode 1616.分割两个字符串得到回文串.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ a = "abkfkzz", b = "xxiouba"
7373

7474
$newStr$由三部分组成:$abkfkba = ab + kfk + ba$
7575

76-
其中$s_1 = ab \in a_{perfix}$,$s_3 = ba \in b_{suffix}$,$ab$和$ba$互为回文串,$s_2 = kfk$自身为回文串。
76+
其中$s_1 = ab \in a_{prefix}$,$s_3 = ba \in b_{suffix}$,$ab$和$ba$互为回文串,$s_2 = kfk$自身为回文串。
7777

7878
**那么思路来了:**
7979

8080
一个指针指向$a$串的首部,另一个指针指向$b$串的尾部,当两个指针所指字符相等时,a指针后移b指针前移,直到两指针相遇或两指针所指不同为止。
8181

82-
+ 如果两指针相遇,则说明$a_{perfix}$和$b_{suffix}$已经互为回文,$s_2$为空即可,直接返回$true$
82+
+ 如果两指针相遇,则说明$a_{prefix}$和$b_{suffix}$已经互为回文,$s_2$为空即可,直接返回$true$
8383
+ 如果两指针所指不同,则a指针前面的部分视为$s_1$,b指针后面的部分视为$s_3$(可以保证$s_1$和$s_3$互为回文),字符串a****字符串b 从a指针到b指针的部分 视为$s_2$,只需要判断$s_2$自身是否为回文串即可。若是则返回true,不是则返回false
8484

85-
上面判断了$a_{perfix} + b_{suffix}$的情况,$b_{perfix} + a_{suffix}$则同理
85+
上面判断了$a_{prefix} + b_{suffix}$的情况,$b_{prefix} + a_{suffix}$则同理
8686

8787
+ 时间复杂度$O(len(a))$
8888
+ 空间复杂度$O(1)$

Solutions/LeetCode 2438.二的幂数组中查询范围内的乘积.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ categories: [题解, LeetCode]
6161
两种方法:
6262

6363
1. 直接暴力从query[0]累乘到query[1]并随时取模
64-
2. 前缀和的思想,使用数组perfix[j]代表$\prod_{0}^{j-1}powers[i]$
64+
2. 前缀和的思想,使用数组prefix[j]代表$\prod_{0}^{j-1}powers[i]$
6565

6666
直接暴力的方法并不会很耗时,因为powers数组中最多30个元素;
6767

@@ -138,10 +138,10 @@ class Solution:
138138
pows.append(1 << th)
139139
th += 1
140140
n >>= 1
141-
perfix = [1] * (len(pows) + 1)
141+
prefix = [1] * (len(pows) + 1)
142142
for i in range(1, len(pows) + 1):
143-
perfix[i] = perfix[i - 1] * pows[i - 1]
144-
return [perfix[q[1] + 1] // perfix[q[0]] % 1000000007 for q in queries]
143+
prefix[i] = prefix[i - 1] * pows[i - 1]
144+
return [prefix[q[1] + 1] // prefix[q[0]] % 1000000007 for q in queries]
145145
```
146146

147147
> 同步发文于[CSDN](https://letmefly.blog.csdn.net/article/details/150227536)和我的[个人博客](https://blog.letmefly.xyz/),原创不易,转载经作者同意后请附上[原文链接](https://blog.letmefly.xyz/2025/08/11/LeetCode%202438.%E4%BA%8C%E7%9A%84%E5%B9%82%E6%95%B0%E7%BB%84%E4%B8%AD%E6%9F%A5%E8%AF%A2%E8%8C%83%E5%9B%B4%E5%86%85%E7%9A%84%E4%B9%98%E7%A7%AF/)哦~

0 commit comments

Comments
 (0)