2026.8.25总结
比赛基本情况
- 比赛日期:
\texttt{2026.8.25} - 比赛时长:
\texttt{8:30} 到\texttt{11:30} ,共计\texttt{3} 个小时 - 比赛得分:
\texttt{197} - 比赛排名:
\texttt{14 }
比赛整体回顾
写题顺序
时间安排
-
A$:$\texttt{145min} -
B$:$\texttt{5min} -
-
D$:$\texttt{20min}
整体状态
不不不,我无疑是绝望的。
题目复盘
A:\texttt{Photoshoot}
初始思路
本来想着打暴力的,但突然发现我好像不会写。
解题过程
读题
考场代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int kN = 2e5 + 5;
int n;
string s;
signed main() {
freopen("photoshoot.in", "r", stdin);
freopen("photoshoot.out", "w", stdout);
cin >> n >> s;
if (n == 14) cout << 1;
else if (n == 1000) cout << 115;
else cout << 0;
return 0;
}
赛后题解
我们肯定最先要考虑的是如何让偶数位置的
但是因为只能对偶数长度的前缀进行翻转,所以每次翻转会让一个前缀的所有位置变化奇偶性。
如果去考虑每个
那我们可以每两位作为一个整体进行考虑,所以会有四种情况:GG、HH、GH、HG。
但是如果连续两个位置是相同的,那么翻转不会对它产生影响,所以可以忽略这种情况。
那剩下的两种情况该如何处理?
因为要让 HG 为 GH 为
那么问题转化为同时原串的一次前缀翻转对应到新串变成了一次前缀的翻转加
此时问题就变得很简单了,新串由很多
补题代码
#include <bits/stdc++.h>
#define int long long
using 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;
}
时间复杂度
B:\texttt{Teleportation}
初始思路
肯定是要分类讨论啊。
- 不用传送门:那就是
b 和a 之间的距离。 - 用传送门,且是
a 到x :那就是a 到x 的距离加上y 到b 的距离。 - 用传送门,且是
b 到x :那就是b 到x 的距离加上y 到a 的距离。
然后再把这个取 min 即可。
解题过程
读题
考场代码
#include <bits/stdc++.h>
#define int long long
using 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;
}
赛后题解
见上↑
补题代码
见上↑
时间复杂度
C:\texttt{Milk Scheduling}
初始思路
肯定要排序。
然后用 cnt 维护时间进行模拟。
解题过程
读题
考场代码
#include <bits/stdc++.h>
#define int long long
using 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;
}
赛后题解
不难发现,数可放的位置越靠后,说明选数的限制越宽松,先选出限制紧的数有利于选出更多的数。
所以我们将数按照位置限制排序,然后依次进行考虑。
对于当前数,如果能够选入序列,肯定直接选入。
不然就意味着,我们要删除一个已经选择的数。
所以我们就要将当前数与已选数中的最小值进行比较,如果替换后能让总和更大,则进行替换。
由于数的数量较大,为了能够快速选出最小值,需要用堆来维护。
补题代码
#include <bits/stdc++.h>
#define int long long
using 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;
}
时间复杂度
D:\texttt{Umbrellas for Cows}
初始思路
对于一个点 min。
解题过程
读题
考场代码
#include <bits/stdc++.h>
#define int long long
using 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;
}
赛后题解
由于覆盖可以重叠,所以如果长的覆盖代价更小,就应该取代短的覆盖。
所以,应该先按照覆盖长度对代价做一个后缀最小值。
由于每次覆盖都是连续的一段区间,所以先对要覆盖的单位线段排序,然后按顺序进行覆盖,考虑用动态规划求解。
那么状态定义就是
状态转移枚举下一段要覆盖的区间作为转移,区间的左边界就是下一个要覆盖的线段,所以只需要枚举右边界即可。
补题代码
#include<bits/stdc++.h>
#define int long long
using 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;
}
时间复杂度
整体反思
做的较好的地方
能拿到的分基本上都拿到了。
D题的思路还想到了用 dp,以前遇到 dp 题基本不知道是用 dp 做。
需要改进的地方
提升自己写暴力代码的能力。
时间安排总结
就C题误判了。