跳到正文

个人记录

2026.8.25总结

SEF_711约 12 分钟
原文
文章信息与版本

文章信息

发布
2026年8月25日
收录
2026年8月25日
更新
2026年11月18日
篇幅
约 12 分钟

版本

  1. v2当前
  2. v1

比赛基本情况

  • 比赛日期:2026.8.25\texttt{2026.8.25}
  • 比赛时长:8:30\texttt{8:30} 到 11:30\texttt{11:30},共计 3\texttt{3} 个小时
  • 比赛得分:197\texttt{197}
  • 比赛排名:14 \texttt{14 }

比赛整体回顾

写题顺序

B→C→D→AB \to C \to D \to A

时间安排

  • AA:145min\texttt{145min}
  • BB:5min\texttt{5min}
  • CC:10min\texttt{10min},额……但后面发现没那么简单。 。 。
  • DD:20min\texttt{20min}

整体状态

不不不,我无疑是绝望的。

题目复盘

A:Photoshoot\texttt{Photoshoot}

初始思路

本来想着打暴力的,但突然发现我好像不会写。

解题过程

读题 →\to 写暴力 →\to 骗分

考场代码

C++
#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;
} 

赛后题解

我们肯定最先要考虑的是如何让偶数位置的 G\texttt{G} 尽可能得多。
但是因为只能对偶数长度的前缀进行翻转,所以每次翻转会让一个前缀的所有位置变化奇偶性。
如果去考虑每个 G\texttt{G} 的变化,未免也太复杂。因此,我们要简化状态。

那我们可以每两位作为一个整体进行考虑,所以会有四种情况:GG、HH、GH、HG。
但是如果连续两个位置是相同的,那么翻转不会对它产生影响,所以可以忽略这种情况。

那剩下的两种情况该如何处理?
因为要让 G\texttt{G} 尽可能在偶数位,那么可以设 HG 为 1\texttt{1},GH 为 0\texttt{0}。
那么问题转化为同时原串的一次前缀翻转对应到新串变成了一次前缀的翻转加 01\texttt{01} 变换,目标就是让新串的 1\texttt{1} 尽可能多。

此时问题就变得很简单了,新串由很多 01\texttt{01} 段组成,我们可以不断的对第一段进行操作,这样翻转不会对第一段产生影响,但第一段会 01\texttt{01} 互换,然后与第二段合并到一起,不断这样操作,最终就可以让串变成全 1\texttt{1} ,这个答案是最优的。

补题代码

C++
#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;
}

时间复杂度

O(N)O(N)

B:Teleportation\texttt{Teleportation}

初始思路

肯定是要分类讨论啊。

  1. 不用传送门:那就是 bb 和 aa 之间的距离。
  2. 用传送门,且是 aa 到 xx:那就是 aa 到 xx 的距离加上 yy 到 bb 的距离。
  3. 用传送门,且是 bb 到 xx:那就是 bb 到 xx 的距离加上 yy 到 aa 的距离。

然后再把这个取 min 即可。

解题过程

读题 →\to 分析 →\to 写代码

考场代码

C++
#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;
}

赛后题解

见上↑

补题代码

见上↑

时间复杂度

O(1)O(1)

C:Milk Scheduling\texttt{Milk Scheduling}

初始思路

肯定要排序。

然后用 cnt 维护时间进行模拟。

解题过程

读题 →\to 写代码

考场代码

C++
#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;
}

赛后题解

不难发现,数可放的位置越靠后,说明选数的限制越宽松,先选出限制紧的数有利于选出更多的数。
所以我们将数按照位置限制排序,然后依次进行考虑。

对于当前数,如果能够选入序列,肯定直接选入。
不然就意味着,我们要删除一个已经选择的数。
所以我们就要将当前数与已选数中的最小值进行比较,如果替换后能让总和更大,则进行替换。

由于数的数量较大,为了能够快速选出最小值,需要用堆来维护。

补题代码

C++
#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;
}

时间复杂度

O(Nlog⁡N)O(N \log N)

D:Umbrellas for Cows\texttt{Umbrellas for Cows}

初始思路

对于一个点 ii,去看看它能不能和前面的点进行合并:算它们的宽度,然后取 min。

解题过程

读题 →\to 分析 →\to 写代码

考场代码

C++
#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;
}

赛后题解

由于覆盖可以重叠,所以如果长的覆盖代价更小,就应该取代短的覆盖。
所以,应该先按照覆盖长度对代价做一个后缀最小值。

由于每次覆盖都是连续的一段区间,所以先对要覆盖的单位线段排序,然后按顺序进行覆盖,考虑用动态规划求解。

那么状态定义就是 dpi,jdp_{i, j} 表示覆盖前 ii 个线段需要 jj 的代价。

状态转移枚举下一段要覆盖的区间作为转移,区间的左边界就是下一个要覆盖的线段,所以只需要枚举右边界即可。

补题代码

C++
#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;
}

时间复杂度

O(N2+M)O(N^2 + M)

整体反思

做的较好的地方

能拿到的分基本上都拿到了。

D题的思路还想到了用 dp,以前遇到 dp 题基本不知道是用 dp 做。

需要改进的地方

提升自己写暴力代码的能力。

时间安排总结

就C题误判了。

原文