版本比较
2026.8.25总结
标题
增加 1 行删除 1 行
112026.8.25总结(未完成)2026.8.25总结正文
增加 305 行删除 2 行
12345667891045 行未改动565758596061626364656667686970717273746275767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365# 比赛基本情况
- 比赛日期:$\texttt{2026.8.25}$- 比赛时长:$\texttt{8:30}$ 到 $\texttt{11:30}$,共计 $\texttt{3}$ 个小时- 比赛得分:$\texttt{197}$- 比赛排名:$\texttt{13}$- 比赛排名:$\texttt{14 }$
# 比赛整体回顾
### 写题顺序45 行未改动```
### 赛后题解
我们肯定最先要考虑的是如何让偶数位置的 $\texttt{G}$ 尽可能得多。 但是因为只能对偶数长度的前缀进行翻转,所以每次翻转会让一个前缀的所有位置变化奇偶性。 如果去考虑每个 $\texttt{G}$ 的变化,未免也太复杂。因此,我们要简化状态。
那我们可以每两位作为一个整体进行考虑,所以会有四种情况:`GG`、`HH`、`GH`、`HG`。 但是如果连续两个位置是相同的,那么翻转不会对它产生影响,所以可以忽略这种情况。
那剩下的两种情况该如何处理? 因为要让 $\texttt{G}$ 尽可能在偶数位,那么可以设 `HG` 为 $\texttt{1}$,`GH` 为 $\texttt{0}$。 那么问题转化为同时原串的一次前缀翻转对应到新串变成了一次前缀的翻转加 $\texttt{01}$ 变换,目标就是让新串的 $\texttt{1}$ 尽可能多。
此时问题就变得很简单了,新串由很多 $\texttt{01}$ 段组成,我们可以不断的对第一段进行操作,这样翻转不会对第一段产生影响,但第一段会 $\texttt{01}$ 互换,然后与第二段合并到一起,不断这样操作,最终就可以让串变成全 $\texttt{1}$ ,这个答案是最优的。
### 补题代码
#```cpp#include <bits/stdc++.h>#define int long longusing namespace std;
int n;string s;int ans;vector<bool> str;signed main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n >> s; s = '#' + s; for(int i = 1; i <= n; i += 2) if(s[i] != s[i + 1]) if(s[i] == 'G') str.push_back(1); else str.push_back(0); for(int i = 1; i < str.size(); i++) if(str[i - 1] != str[i]) ans++; if(str.empty() == 1) cout << ans; else cout << ans + str[str.size() - 1]; return 0;}```
### 时间复杂度
$O(N)$
## B:$\texttt{Teleportation}$
### 初始思路
肯定是要分类讨论啊。
1. 不用传送门:那就是 $b$ 和 $a$ 之间的距离。2. 用传送门,且是 $a$ 到 $x$:那就是 $a$ 到 $x$ 的距离加上 $y$ 到 $b$ 的距离。3. 用传送门,且是 $b$ 到 $x$:那就是 $b$ 到 $x$ 的距离加上 $y$ 到 $a$ 的距离。
然后再把这个取 `min` 即可。
### 解题过程
读题 $\to$ 分析 $\to$ 写代码
### 考场代码
```cpp#include <bits/stdc++.h>#define int long longusing namespace std;
int a, b, x, y;signed main() { freopen("teleport.in", "r", stdin); freopen("teleport.out", "w", stdout); cin >> a >> b >> x >> y; if (a > b) swap(a, b); if (x > y) swap(x, y); int ans1 = abs(a - b); int ans2 = abs(a - x) + abs(b - y); int ans3 = abs(b - x) + abs(a - y); cout << min(ans1, min(ans2, ans3)); return 0;}
```
### 赛后题解
见上↑
### 补题代码
见上↑
### 时间复杂度
$O(1)$
## C:$\texttt{Milk Scheduling}$
### 初始思路
肯定要排序。
然后用 `cnt` 维护时间进行模拟。
### 解题过程
读题 $\to$ 写代码
### 考场代码
```cpp#include <bits/stdc++.h>#define int long longusing namespace std;
const int kN = 1e4 + 5;int n;int cnt, sum;struct node { int g, d;} a[kN];bool cmp(const node &x, const node &y) { if (x.d != y.d) return x.d < y.d; return x.g > y.g;}signed main() { freopen("msched.in", "r", stdin); freopen("msched.out", "w", stdout); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].g >> a[i].d; sort(a + 1, a + 1 + n, cmp); for (int i = 1; i <= n; i++) if (a[i].d > cnt) cnt++, sum += a[i].g; cout << sum; return 0;}
```
### 赛后题解
不难发现,数可放的位置越靠后,说明选数的限制越宽松,先选出限制紧的数有利于选出更多的数。 所以我们将数按照位置限制排序,然后依次进行考虑。
对于当前数,如果能够选入序列,肯定直接选入。 不然就意味着,我们要删除一个已经选择的数。 所以我们就要将当前数与已选数中的最小值进行比较,如果替换后能让总和更大,则进行替换。
由于数的数量较大,为了能够快速选出最小值,需要用堆来维护。
### 补题代码
```cpp#include <bits/stdc++.h>#define int long longusing namespace std;
const int kN = 1e4 + 5;int n;int ans;struct node{ int g, d;} a[kN];bool cmp(const node &x, const node &y){ return x.d < y.d;}priority_queue<int> q;signed main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].g >> a[i].d; sort(a + 1, a + 1 + n, cmp); for (int i = 1, t = 1; i <= n; i++) { if (a[i].d < t) { int x = -q.top(); if(x < a[i].g) { q.pop(); q.push(-a[i].g); ans += a[i].g - x; } } if (a[i].d >= t) { q.push(-a[i].g); ans += a[i].g; t++; } } cout << ans; return 0;}```
### 时间复杂度
$O(N \log N)$
## D:$\texttt{Umbrellas for Cows}$
### 初始思路
对于一个点 $i$,去看看它能不能和前面的点进行合并:算它们的宽度,然后取 `min`。
### 解题过程
读题 $\to$ 分析 $\to$ 写代码
### 考场代码
```cpp#include <bits/stdc++.h>#define int long longusing namespace std;
const int kN = 5e3 + 5, kM = 1e5 + 5, INF = 1e18;int n, m;int a[kN], c[kM], dp[kN];signed main() { freopen("umbrella.in", "r", stdin); freopen("umbrella.out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n); for (int i = 1; i <= m; i++) cin >> c[i]; for (int i = 1; i <= n; i++) dp[i] = INF; for (int i = 1; i <= n; i++) for (int j = 1; j <= i; j++) { int len = a[i] - a[j] + 1; dp[i] = min(dp[i], dp[j - 1] + c[len]); } cout << dp[n]; return 0;}```
### 赛后题解
由于覆盖可以重叠,所以如果长的覆盖代价更小,就应该取代短的覆盖。 所以,应该先按照覆盖长度对代价做一个后缀最小值。
由于每次覆盖都是连续的一段区间,所以先对要覆盖的单位线段排序,然后按顺序进行覆盖,考虑用动态规划求解。
那么状态定义就是 $dp_{i, j}$ 表示覆盖前 $i$ 个线段需要 $j$ 的代价。
状态转移枚举下一段要覆盖的区间作为转移,区间的左边界就是下一个要覆盖的线段,所以只需要枚举右边界即可。
### 补题代码
```cpp#include<bits/stdc++.h>#define int long longusing namespace std;
const int kN = 1e5 + 5;int n, m;int a[kN], c[kN], dp[kN];signed main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n); for (int i = 1; i <= m; i++) cin >> c[i]; for (int i = m - 1; i >= 1; i--) c[i] = min(c[i], c[i + 1]); memset(dp, 0x3f, sizeof dp); dp[0] = 0; for (int i = 1; i <= n; i++) { dp[i] = dp[i - 1] + c[1]; for (int j = 1; j < i; j++) dp[i] = min(dp[i], dp[j - 1] + c[a[i] - a[j] + 1]); } cout << dp[n]; return 0;}```
### 时间复杂度
$O(N^2 + M)$
# 整体反思
### 做的较好的地方
能拿到的分基本上都拿到了。
D题的思路还想到了用 `dp`,以前遇到 `dp` 题基本不知道是用 `dp` 做。
### 需要改进的地方
提升自己写暴力代码的能力。
### 时间安排总结
就C题误判了。