20260725总结
一、比赛基本情况
- 比赛日期:2026.8.25
- 比赛时长:3h
- 比赛得分:87
- 比赛排名:31
二、比赛整体回顾
三、题目复盘
T1:Photoshoot B
- 本题得分:10
- 开始时间:10:00
- 结束时间:11:30
- 总用时:1.5h
初始思路
模拟
考场解题过程
枚举左边界和右边界然后翻转并计数
考场代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
char s[N];
signed main() {
freopen("photoshoot.in", "r", stdin);
freopen("photoshoot.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, ans = INT_MAX;
cin >> n >> s;
for (int i = 0; i < n; i++) {
if (s[i]== 'G') {
int cnt = 0, cntt = 0;
for (int j = 0; j <= i; j++) if (s[j] == 'G' && j % 2 == 0) cnt++;
reverse(s, s + i);
for (int j = 0; j <= i; j++) if (s[j] == 'G' && j % 2 == 1) cntt++;
ans = min(ans, max(cnt, cntt));
}
}
cout << ans;
return 0;
}赛后题解
肯定最先要考虑的是如何让偶数位置的 G 尽可能得多,但是因为只能对偶数长度的前缀进行翻转,所以每次翻转会让一个前缀的所有位置变化奇偶性,如果去考虑每个 G 的变化,太复杂。简化状态
每两位作为一个整体进行考虑,所以会有四种情况:GG、HH、GH、HG,但是如果连续两个位置是相同的,那么翻转不会对它产生影响,所以可以忽略这种情况
剩下的两种情况要让 G 尽可能在偶数位,那么可以设 HG 为 1,GH 为 0
问题转化为同时原串的一次前缀翻转对应到新串变成了一次前缀的翻转加 01 变换,目标就是让新串的 1 尽可能多
问题就变得很简单了,新串由 01 段组成,不断的对第一段进行操作,这样翻转不会对第一段产生影响,但第一段会 01 互换,然后与第二段合并到一起,不断这样操作,最终就可以让串变成全 1 ,这个答案是最优的
补题代码
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
string t = "";
for (int i = 0; i < n - 1; i += 2)
if (s[i] != s[i + 1]) {
if(s[i] == 'G') t += '1';
else t += '0';
}
int sum = 0;
for (int i = 1; i < t.size(); i++)
if (t[i - 1] != t[i])
sum++;
int tot = t.size() - 1;
tot = max(tot, 1);
if (t[tot] == '1')
sum++;
cout << sum;
return 0;
}复杂度
- 时间复杂度:
本题总结
并未想到可以简化状态
T2:Teleportation B
- 本题得分:40
- 开始时间:8:30
- 结束时间:8:40
- 总用时:10min
初始思路
输出直接从 去 的距离和 去传送门传送到 再去 的距离的
考场解题过程
按照思路模拟,但是注意到可能会出现 的情况,所以先判断要不要 swap,然后再去输出
考场代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
freopen("teleport.in", "r", stdin);
freopen("teleport.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int a, b, x, y;
cin >> a >> b >> x >> y;
int ans = b - a + 1;
if (x > y) swap(x, y);
cout << min(ans, abs(a - x) + abs(y - b));
return 0;
}赛后题解
注意到可能会出现 的情况,所以还需判断是否需要将 和 swap
然后发现 并不会算入拖拉机的行驶范围内(直接从 去 ),因此这里不需在 b - a 后再次 -1
补题代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int a, b, x, y;
cin >> a >> b >> x >> y;
if (a > b) swap(a, b);
int ans = b - a;
if (x > y) swap(x, y);
cout << min(ans, abs(a - x) + abs(y - b));
return 0;
}复杂度
- 时间复杂度:
本题总结
主要还是没有思考全面
T3:Milk Scheduling S
- 本题得分:36
- 开始时间:8:40
- 结束时间:9:45
- 总用时:65min
初始思路
两次贪心
考场解题过程
先排序然后贪心出 和 ,然后再排序 和 ,最后再贪心出答案
考场代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 10005;
struct node {
int g, d;
} a[N], b[N], c[N];
bool cmp(node x, node y) {
if (x.d == y.d)
return x.g > y.g;
return x.d < y.d;
}
signed main() {
freopen("msched.in", "r", stdin);
freopen("msched.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i].g >> a[i].d;
sort(a + 1, a + 1 + n, cmp);
int t = 0, ans = 0, tot = 0, cnt = 0;
for (int i = 1; i <= n; i++) {
if (a[i].d > t) {
t++, ans += a[i].g;
c[++tot].g = a[i].g;
c[tot].d = a[i].d;
} else {
b[++cnt].g = a[i].g;
b[cnt].d = a[i].d;
}
}
sort(c + 1, c + 1 + tot, cmp);
sort(b + 1, b + 1 + cnt, cmp);
int tott = 0;
for (int i = 1; i <= tot; i++) {
while (b[tott].d <= c[i].d && tott <= cnt) tott++;
while (b[tott].g <= c[i].g && tott <= cnt) tott++;
if (tott != cnt + 1) {
ans += (b[tott].g - c[i].g);
c[i].d = b[tott].d;
c[i].g = b[tott].g;
b[tott].d = b[tott].g = 0;
}
tott = 1;
}
cout << ans;
return 0;
}
赛后题解
数能放的位置越靠后,说明选数的限制越宽松,先选出限制紧的数有利于选出更多的数,所以将数按照位置限制排序,然后依次进行考虑
对于当前数,如果能够选入序列,肯定直接选入。否则就意味如果要选当前数,就必然要删除一个已选的数。因此可以将当前数与已选数中的最小值进行比较,如果替换后能让总和更大,则进行替换
因为选取的数都是满足位置限制的,删除任意一个数,会让靠后的数都往前移动,必然还是满足位置限制,所以是可行的
由于数的数量较大,为了能够快速选出最小值,需要用堆来维护
复杂度
- 时间复杂度:
补题代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
priority_queue<int, vector<int>, greater<int> > q;
struct node {
int g, d;
}a[N];
bool cmp(node x, node y) {
if (x.d == y.d) return x.g > y.g;
return x.d < y.d;
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i].g >> a[i].d;
sort(a + 1, a + n + 1, cmp);
int ans = 0;
for (int i = 1; i <= n; i++)
if (q.size() < a[i].d) {
q.push(a[i].g);
ans += a[i].g;
}
else {
while (q.size() >= a[i].d && q.top() < a[i].g) {
ans -= q.top();
q.pop();
}
if (q.size() < a[i].d || q.top() <= a[i].g) {
q.push(a[i].g);
ans += a[i].g;
}
}
cout << ans;
return 0;
}本题总结
没想到可以使用小根堆
T4:Umbrellas for Cows S
- 本题得分:0
- 开始时间:9:45
- 结束时间:9:50
- 总用时:5min
初始思路
骗分是个好东西
考场解题过程
直接输出可以直接遮住说有奶牛的伞的价格
考场代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5;
int x[N], c[N];
signed main() {
freopen("umbrella.in", "r", stdin);
freopen("umbrella.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
int minn = INT_MAX, maxx = 0;
for (int i = 1; i <= n; i++) cin >> x[i], minn = min(minn, x[i]), maxx = max(maxx, x[i]);
for (int i = 1; i <= m; i++) cin >> c[i];
cout << c[maxx - minn + 1];
return 0;
}
赛后题解
由于覆盖可以重叠,所以如果长的覆盖代价更小,就应该取代短的覆盖。所以应该先按照覆盖长度对代价做一个后缀最小值
由于每次覆盖都是连续的一段区间,所以先对要覆盖的单位线段排序,然后按顺序进行覆盖,考虑用动态规划求解
那么状态定义就是 表示覆盖前 个线段需要 的代价
状态转移枚举下一段要覆盖的区间作为转移,区间的左边界就是下一个要覆盖的线段,所以只需要枚举右边界即可
补题代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5;
int a[N], c[N], dp[N];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, m;
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;
}复杂度
- 时间复杂度:
本题总结
没想到解决方法,所以就骗分了
四、整体反思
做得较好的地方
时间安排较好
需要改进的地方
思维不足
时间安排总结
在 题没有想到解决方法时并未一直思考,而是直接跳过,做完剩下的题目之后,再来思考