Skip to content

Commit c206f9a

Browse files
committed
archive: before.换设备
1 parent eb70d9b commit c206f9a

File tree

8 files changed

+145
-18
lines changed

8 files changed

+145
-18
lines changed

.commitmsg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2054: AC.cpp (#1275) - AC,85.19%,53.70%
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-12-23 13:34:22
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-23 18:58:01
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
int maxTwoEvents(vector<vector<int>>& events) {
14+
sort(events.begin(), events.end(), [](const vector<int>& a, const vector<int>& b) {
15+
return a[1] < b[1];
16+
});
17+
vector<pair<int, int>> maxValue;
18+
int singleMax = 0, pairMax = 0;
19+
for (vector<int>& e : events) {
20+
vector<pair<int, int>>::iterator it = lower_bound(maxValue.begin(), maxValue.end(), e[0], [](const pair<int, int>& p, int value) {
21+
return p.first < value;
22+
});
23+
if (it != maxValue.begin()) {
24+
pairMax = max(pairMax, (--it)->second + e[2]);
25+
}
26+
singleMax = max(singleMax, e[2]);
27+
maxValue.push_back({e[1], singleMax});
28+
}
29+
return max(pairMax, singleMax);
30+
}
31+
};
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
title: 2054.两个最好的不重叠活动:
3+
date: 2025-12-23 19:00:09
4+
tags: [题解, LeetCode, 中等, 数组, 二分查找, 动态规划, 排序, 堆(优先队列)]
5+
categories: [题解, LeetCode]
6+
---
7+
8+
# 【LetMeFly】2054.两个最好的不重叠活动:
9+
10+
力扣题目链接:[https://leetcode.cn/problems/two-best-non-overlapping-events/](https://leetcode.cn/problems/two-best-non-overlapping-events/)
11+
12+
<p>给你一个下标从 <strong>0</strong>&nbsp;开始的二维整数数组&nbsp;<code>events</code>&nbsp;,其中&nbsp;<code>events[i] = [startTime<sub>i</sub>, endTime<sub>i</sub>, value<sub>i</sub>]</code>&nbsp;。第&nbsp;<code>i</code>&nbsp;个活动开始于&nbsp;<code>startTime<sub>i</sub></code>&nbsp;,结束于&nbsp;<code>endTime<sub>i</sub></code>&nbsp;,如果你参加这个活动,那么你可以得到价值&nbsp;<code>value<sub>i</sub></code>&nbsp;。你 <strong>最多</strong>&nbsp;可以参加&nbsp;<strong>两个时间不重叠</strong>&nbsp;活动,使得它们的价值之和 <strong>最大</strong>&nbsp;。</p>
13+
14+
<p>请你返回价值之和的 <strong>最大值</strong>&nbsp;。</p>
15+
16+
<p>注意,活动的开始时间和结束时间是 <strong>包括</strong>&nbsp;在活动时间内的,也就是说,你不能参加两个活动且它们之一的开始时间等于另一个活动的结束时间。更具体的,如果你参加一个活动,且结束时间为 <code>t</code>&nbsp;,那么下一个活动必须在&nbsp;<code>t + 1</code>&nbsp;或之后的时间开始。</p>
17+
18+
<p>&nbsp;</p>
19+
20+
<p><strong>示例 1:</strong></p>
21+
22+
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/09/21/picture5.png" style="width: 400px; height: 75px;"></p>
23+
24+
<pre><b>输入:</b>events = [[1,3,2],[4,5,2],[2,4,3]]
25+
<b>输出:</b>4
26+
<strong>解释:</strong>选择绿色的活动 0 和 1 ,价值之和为 2 + 2 = 4 。
27+
</pre>
28+
29+
<p><strong>示例 2:</strong></p>
30+
31+
<p><img alt="Example 1 Diagram" src="https://assets.leetcode.com/uploads/2021/09/21/picture1.png" style="width: 400px; height: 77px;"></p>
32+
33+
<pre><b>输入:</b>events = [[1,3,2],[4,5,2],[1,5,5]]
34+
<b>输出:</b>5
35+
<strong>解释:</strong>选择活动 2 ,价值和为 5 。
36+
</pre>
37+
38+
<p><strong>示例 3:</strong></p>
39+
40+
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/09/21/picture3.png" style="width: 400px; height: 66px;"></p>
41+
42+
<pre><b>输入:</b>events = [[1,5,3],[1,5,1],[6,6,5]]
43+
<b>输出:</b>8
44+
<strong>解释:</strong>选择活动 0 和 2 ,价值之和为 3 + 5 = 8 。</pre>
45+
46+
<p>&nbsp;</p>
47+
48+
<p><strong>提示:</strong></p>
49+
50+
<ul>
51+
<li><code>2 &lt;= events.length &lt;= 10<sup>5</sup></code></li>
52+
<li><code>events[i].length == 3</code></li>
53+
<li><code>1 &lt;= startTime<sub>i</sub> &lt;= endTime<sub>i</sub> &lt;= 10<sup>9</sup></code></li>
54+
<li><code>1 &lt;= value<sub>i</sub> &lt;= 10<sup>6</sup></code></li>
55+
</ul>
56+
57+
58+
59+
## 解题方法:xx
60+
61+
11111
62+
63+
+ 时间复杂度$O(N^2)$
64+
+ 空间复杂度$O(N\log N)$
65+
66+
### AC代码
67+
68+
#### C++
69+
70+
```cpp
71+
/*
72+
* @Author: LetMeFly
73+
* @Date: 2025-12-23 13:34:22
74+
* @LastEditors: LetMeFly.xyz
75+
* @LastEditTime: 2025-12-23 18:58:01
76+
*/
77+
#if defined(_WIN32) || defined(__APPLE__)
78+
#include "_[1,2]toVector.h"
79+
#endif
80+
81+
class Solution {
82+
public:
83+
int maxTwoEvents(vector<vector<int>>& events) {
84+
sort(events.begin(), events.end(), [](const vector<int>& a, const vector<int>& b) {
85+
return a[1] < b[1];
86+
});
87+
vector<pair<int, int>> maxValue;
88+
int singleMax = 0, pairMax = 0;
89+
for (vector<int>& e : events) {
90+
vector<pair<int, int>>::iterator it = lower_bound(maxValue.begin(), maxValue.end(), e[0], [](const pair<int, int>& p, int value) {
91+
return p.first < value;
92+
});
93+
if (it != maxValue.begin()) {
94+
pairMax = max(pairMax, (--it)->second + e[2]);
95+
}
96+
singleMax = max(singleMax, e[2]);
97+
maxValue.push_back({e[1], singleMax});
98+
}
99+
return max(pairMax, singleMax);
100+
}
101+
};
102+
```
103+
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/)哦~
105+
>
106+
> 千篇源码题解[已开源](https://github.com/LetMeFly666/LeetCode)

Solutions/Other-English-LearningNotes-SomeWords.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,9 @@ categories: [自用]
16881688
|||
16891689
|imprison|v. 监禁,束缚,关押,入狱|
16901690
|satisfactorily|adv. 满意地,可靠地,顺心|
1691+
|||
1692+
|deliberation|n. 审议,考虑,商议,细想|
1693+
|vaccination|n. 预防接种,牛痘疤|
16911694

16921695
+ 这个web要是能设计得可以闭眼(完全不睁眼)键盘控制背单词就好了。
16931696
+ 也许可以加个AI用最近词编故事功能(返回接口中支持标注所使用单词高亮?)

Solutions/Other-Japanese-LearningNotes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ xx型
253253
|吸い(すい)||
254254
|もうし|(打电话)叫|
255255
|持ち(もち)|提/有|
256+
|転び(転び)|摔倒|
256257
|いり|需要|
257258
|コスプレ|角色扮演(cosplay)|
258259
|離れ(はなれ)|离开|
@@ -789,6 +790,8 @@ xx型
789790
|調子(ちょうし)|状态/身体|
790791
|手(て)||
791792
|足(あし)||
793+
|腕(うで)|手臂|
794+
|傷(きず)||
792795
|||
793796
|痛い(いたい)|痛的|
794797
|元気(げんき)|(身体)很好|

a.c

Lines changed: 0 additions & 15 deletions
This file was deleted.

a.ps1

Lines changed: 0 additions & 1 deletion
This file was deleted.

todo

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
sync LeetCode-test repo
2-
rm a.c a.ps1
1+
daka
32
write a script to delete origin/copilot*

0 commit comments

Comments
 (0)