Skip to content

Commit 2577f49

Browse files
committed
update: 添加问题“2054.两个最好的不重叠活动”的代码和题解 (#1276)
2054: AC.cpp (#1275) - AC,85.19%,53.70% Signed-off-by: LetMeFly666 <[email protected]>
1 parent c206f9a commit 2577f49

File tree

4 files changed

+124
-18
lines changed

4 files changed

+124
-18
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@
696696
|2044.统计按位或能得到最大值的子集数目|中等|<a href="https://leetcode.cn/problems/count-number-of-maximum-bitwise-or-subsets/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/07/28/LeetCode%202044.%E7%BB%9F%E8%AE%A1%E6%8C%89%E4%BD%8D%E6%88%96%E8%83%BD%E5%BE%97%E5%88%B0%E6%9C%80%E5%A4%A7%E5%80%BC%E7%9A%84%E5%AD%90%E9%9B%86%E6%95%B0%E7%9B%AE/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/149725900" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-number-of-maximum-bitwise-or-subsets/solutions/3736072/letmefly-2044tong-ji-an-wei-huo-neng-de-97g9f/" target="_blank">LeetCode题解</a>|
697697
|2048.下一个更大的数值平衡数|中等|<a href="https://leetcode.cn/problems/next-greater-numerically-balanced-number/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/12/09/LeetCode%202048.%E4%B8%8B%E4%B8%80%E4%B8%AA%E6%9B%B4%E5%A4%A7%E7%9A%84%E6%95%B0%E5%80%BC%E5%B9%B3%E8%A1%A1%E6%95%B0/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/134900679" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/next-greater-numerically-balanced-number/solutions/2560353/letmefly-2048xia-yi-ge-geng-da-de-shu-zh-7p4t/" target="_blank">LeetCode题解</a>|
698698
|2050.并行课程III|困难|<a href="https://leetcode.cn/problems/parallel-courses-iii/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/07/28/LeetCode%202050.%E5%B9%B6%E8%A1%8C%E8%AF%BE%E7%A8%8BIII/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/131973511" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/parallel-courses-iii/solutions/2362142/letmefly-2050bing-xing-ke-cheng-iiidfs-b-9tuc/" target="_blank">LeetCode题解</a>|
699+
|2054.两个最好的不重叠活动|中等|<a href="https://leetcode.cn/problems/two-best-non-overlapping-events/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/12/23/LeetCode%202054.%E4%B8%A4%E4%B8%AA%E6%9C%80%E5%A5%BD%E7%9A%84%E4%B8%8D%E9%87%8D%E5%8F%A0%E6%B4%BB%E5%8A%A8/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/156207232" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/two-best-non-overlapping-events/solutions/3864227/letmefly-2054liang-ge-zui-hao-de-bu-zhon-37h9/" target="_blank">LeetCode题解</a>|
699700
|2065.最大化一张图中的路径价值|困难|<a href="https://leetcode.cn/problems/maximum-path-quality-of-a-graph/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/07/01/LeetCode%202065.%E6%9C%80%E5%A4%A7%E5%8C%96%E4%B8%80%E5%BC%A0%E5%9B%BE%E4%B8%AD%E7%9A%84%E8%B7%AF%E5%BE%84%E4%BB%B7%E5%80%BC/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/140101479" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/maximum-path-quality-of-a-graph/solutions/2827788/letmefly-2065zui-da-hua-yi-zhang-tu-zhon-vvkl/" target="_blank">LeetCode题解</a>|
700701
|2070.每一个查询的最大美丽值|中等|<a href="https://leetcode.cn/problems/most-beautiful-item-for-each-query/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/03/09/LeetCode%202070.%E6%AF%8F%E4%B8%80%E4%B8%AA%E6%9F%A5%E8%AF%A2%E7%9A%84%E6%9C%80%E5%A4%A7%E7%BE%8E%E4%B8%BD%E5%80%BC/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/146132104" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/most-beautiful-item-for-each-query/solutions/3603183/letmefly-2070mei-yi-ge-cha-xun-de-zui-da-brpw/" target="_blank">LeetCode题解</a>|
701702
|2073.买票需要的时间|简单|<a href="https://leetcode.cn/problems/time-needed-to-buy-tickets/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/10/03/LeetCode%202073.%E4%B9%B0%E7%A5%A8%E9%9C%80%E8%A6%81%E7%9A%84%E6%97%B6%E9%97%B4/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/142691600" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/time-needed-to-buy-tickets/solutions/2937796/letmefly-2073mai-piao-xu-yao-de-shi-jian-i1pt/" target="_blank">LeetCode题解</a>|

Solutions/LeetCode 2054.两个最好的不重叠活动.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
2-
title: 2054.两个最好的不重叠活动:
3-
date: 2025-12-23 19:00:09
4-
tags: [题解, LeetCode, 中等, 数组, 二分查找, 动态规划, 排序, 堆(优先队列)]
2+
title: 2054.两个最好的不重叠活动:二分查找
3+
date: 2025-12-23 23:45:19
4+
tags: [题解, LeetCode, 中等, 数组, 二分查找, 动态规划, 排序]
55
categories: [题解, LeetCode]
6+
index_img: https://assets.leetcode.com/uploads/2021/09/21/picture5.png
67
---
78

8-
# 【LetMeFly】2054.两个最好的不重叠活动:
9+
# 【LetMeFly】2054.两个最好的不重叠活动:二分查找
910

1011
力扣题目链接:[https://leetcode.cn/problems/two-best-non-overlapping-events/](https://leetcode.cn/problems/two-best-non-overlapping-events/)
1112

@@ -56,28 +57,27 @@ categories: [题解, LeetCode]
5657

5758

5859

59-
## 解题方法:xx
60+
## 解题方法:二分查找
6061

61-
11111
62+
如果只能选一个event,那么好说,哪个价值大选哪个;如果一定要选两个event,假设第二个event选事件e,那么第一个event一定要选结束时间早于e开始时间的所有事件中价值最大的那个。
6263

63-
+ 时间复杂度$O(N^2)$
64-
+ 空间复杂度$O(N\log N)$
64+
很显然,为了枚举第一个event的可选范围,可以以结束时间为依据对所有event按从小到大排个序。
65+
66+
接着使用一个(有序)数组maxValue,数组中存放的内容是:到xx时刻为止,单个event的最大价值是多少。排序依据是结束时间。
67+
68+
遍历所有事件,对于某事件e,二分查找maxValue中小于e开始时间中最大的那个,其值加上e的价值即为第二个event选e情况下的最优解。之后更新e结束时间的单个事件最大值。
69+
70+
+ 时间复杂度$O(n\log n)$,其中$n=len(events)$
71+
+ 空间复杂度$O(n)$
6572

6673
### AC代码
6774

6875
#### C++
6976

7077
```cpp
7178
/*
72-
* @Author: LetMeFly
73-
* @Date: 2025-12-23 13:34:22
74-
* @LastEditors: LetMeFly.xyz
7579
* @LastEditTime: 2025-12-23 18:58:01
7680
*/
77-
#if defined(_WIN32) || defined(__APPLE__)
78-
#include "_[1,2]toVector.h"
79-
#endif
80-
8181
class Solution {
8282
public:
8383
int maxTwoEvents(vector<vector<int>>& events) {
@@ -101,6 +101,6 @@ public:
101101
};
102102
```
103103
104-
> 同步发文于[CSDN](https://letmefly.blog.csdn.net/article/details/--------------------------)和我的[个人博客](https://blog.letmefly.xyz/),原创不易,转载经作者同意后请附上[原文链接](https://blog.letmefly.xyz/2025/12/23/LeetCode%202054.%E4%B8%A4%E4%B8%AA%E6%9C%80%E5%A5%BD%E7%9A%84%E4%B8%8D%E9%87%8D%E5%8F%A0%E6%B4%BB%E5%8A%A8/)哦~
104+
> 同步发文于[CSDN](https://letmefly.blog.csdn.net/article/details/156207232)和我的[个人博客](https://blog.letmefly.xyz/),原创不易,转载经作者同意后请附上[原文链接](https://blog.letmefly.xyz/2025/12/23/LeetCode%202054.%E4%B8%A4%E4%B8%AA%E6%9C%80%E5%A5%BD%E7%9A%84%E4%B8%8D%E9%87%8D%E5%8F%A0%E6%B4%BB%E5%8A%A8/)哦~
105105
>
106106
> 千篇源码题解[已开源](https://github.com/LetMeFly666/LeetCode)

log.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-12-23 22:37:57
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-12-23 22:43:45
6+
'''
7+
8+
import re
9+
from typing import Optional
10+
from datetime import datetime
11+
12+
INPUT_FILE = "C:/Users/LetMe/Desktop/let_proc_snapshot.log"
13+
OUTPUT_FILE = "C:/Users/LetMe/Desktop/proc_snapshot_5min.log"
14+
15+
# 匹配头部时间行
16+
HEADER_RE = re.compile(r"^===== (.+) =====$")
17+
18+
def parse_time(line: str) -> Optional[datetime]:
19+
m = HEADER_RE.match(line.strip())
20+
if not m:
21+
return None
22+
return datetime.strptime(m.group(1), "%Y-%m-%d %H:%M:%S")
23+
24+
def should_keep(ts: datetime) -> bool:
25+
return ts.minute % 5 == 0
26+
27+
def main():
28+
with open(INPUT_FILE, "r", encoding="utf-8") as fin, \
29+
open(OUTPUT_FILE, "w", encoding="utf-8") as fout:
30+
31+
block_lines = []
32+
block_time = None
33+
34+
for line in fin:
35+
ts = parse_time(line)
36+
if ts:
37+
# 新 block 开始,先处理上一个
38+
if block_time and should_keep(block_time):
39+
fout.writelines(block_lines)
40+
41+
block_lines = [line]
42+
block_time = ts
43+
else:
44+
block_lines.append(line)
45+
46+
# 文件结束,别忘了最后一个 block
47+
if block_time and should_keep(block_time):
48+
fout.writelines(block_lines)
49+
50+
print(f"Resample done: {OUTPUT_FILE}")
51+
52+
if __name__ == "__main__":
53+
main()

todo

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,54 @@
1-
daka
2-
write a script to delete origin/copilot*
1+
看下2054最优解 看下copilot评论
2+
write a script to delete origin/copilot*
3+
article - 服务器内存泄漏分析 pkill -f "manage.py crontab run"
4+
5+
豆包搜文章
6+
cdn.letmefly.xyz/img/blog/DoubaoChatSearch/whenEnter.png
7+
how2use.jpg
8+
chatResult.jpg
9+
{
10+
"pluginId": "Send_Message",
11+
"payload": {
12+
"text": "letleet blog到底有多少宝藏"
13+
}
14+
}
15+
16+
{
17+
"pluginId": "Send_Message",
18+
"payload": {
19+
"text": "letleet blog到底有多少宝藏",
20+
"reportParams": {
21+
"content_source": "paste",
22+
"content_source_template_id": "",
23+
"send_source": "guidance_page",
24+
"scene": "keyboard",
25+
"is_long_file": 0,
26+
"new_guidance": "1",
27+
"is_from_screen_shot": 0,
28+
"is_from_new_tab": 1
29+
},
30+
"conversationId": "local_61827421334957",
31+
"extraExt": {
32+
"input_skill": "{\"skill_type\":20}",
33+
"use_deep_think": "0"
34+
},
35+
"loginSource": "new_tab",
36+
"startJumpTime": 1766473291953
37+
},
38+
"pfTrackParams": {
39+
"startJumpTime": 1766473291953,
40+
"phase1EventName": "pc_new_tab_chat_open_jump_phase1_duration",
41+
"phase2EventName": "pc_new_tab_chat_open_jump_phase2_duration",
42+
"phase3EventName": "pc_new_tab_chat_open_jump_phase3_duration",
43+
"phaseNavEventName": "pc_new_tab_chat_open_jump_phasenav_duration",
44+
"phaseChatRenderEventName": "pc_new_tab_chat_open_jump_chatrender_duration"
45+
},
46+
"options": {
47+
"deepThinkingActiveType": "0",
48+
"superTaskStatus": {
49+
"switchValue": 0,
50+
"taskMode": 0,
51+
"safeToken": ""
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)