2026.7.18 总结
测试基本情况
- 比赛日期:
\texttt{2026.7.18} - 比赛时长:
\texttt{8:30} 到\texttt{11:30} ,共计\texttt{3} 个小时 - 比赛得分:
\texttt{297} - 比赛排名:
\texttt{5} 测试基本回顾
写题顺序
C \to D \to B \to A 时间安排
-
A$:$\texttt{148min} -
B$:$\texttt{7min} -
-
D$:$\texttt{20min}
虽然但是有点离谱
整体状态
挺好的,虽然说我在读
题目复盘
A: \texttt{drought}
初始思路
本来想着打暴力,结果发现有点难写(?,就骗了分。 。 。
解题过程
读题
考场代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
freopen("drought.in", "r", stdin);
freopen("drought.out", "w", stdout);
int t;
cout << "14\n16\n-1\n-1\n-1";
return 0;
}
赛后题解
我们思考一下,这个题在哪里把你卡住了,肯定是你不知道每个元素最终的值。然后我们可以想到枚举最终值,但是数据范围很不友好,足足有
那怎么做呢?我们试着找找规律。
为了方便后面表示,我们设最终值为
-
\texttt{[1,2]}$ 的操作次数为 $a_1 - x$,若 $n = 1$,则有 $a_1 - x = 0 -
\texttt{[2,3]}$ 的操作次数为 $a_2 - a_1$,若 $n = 2$,则有 $a_2 - a_1 = 0 -
\texttt{[3,4]}$ 的操作次数为 $a_3 - (a_2 - a_1) - x$,若 $n = 3$,则有 $a_3 - (a_2 - a_1) - x = 0 -
\texttt{[4,5]}$ 的操作次数为 $a_4 - a_3 + a_2 - a_1$,若 $n = 3$,则有 $a_4 - a_3 + a_2 - a_1 = 0 ……
然后我们就会发现一个规律:当位置
而且,因为每次只能将相邻两个位置同时减少,所以必须确保任意相邻两位的操作次数不少于
所以,我们需要对所有带
补题代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int kN = 1e5 + 5;
int n;
int a[kN];
void work() {
cin >> n;
memset(a, 0x3f, sizeof a);
int ans = 0;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 2; i < n; i++) {
if(a[i] > a[i + 1]) {
int t = a[i] - a[i + 1];
a[i - 1] -= t;
a[i] -= t;
ans += t * 2;
}
if(a[i] > a[i - 1]) {
int t = a[i] - a[i - 1];
a[i + 1] -= t;
a[i] -= t;
ans += t * 2;
}
}
for(int i = n - 1; i > 1; i--) {
if(a[i] > a[i + 1]) {
int t = a[i] - a[i + 1];
a[i - 1] -= t;
a[i] -= t;
ans += t * 2;
}
if(a[i] > a[i - 1]) {
int t = a[i] - a[i - 1];
a[i + 1] -= t;
a[i] -= t;
ans += t * 2;
}
}
for(int i = 1; i < n; i++)
if(a[i] != a[i + 1] || a[i] < 0) {
cout << "-1\n";
return;
}
cout << ans << "\n";
}
signed main() {
int t;
cin >> t;
while(t--)
work();
return 0;
}
时间复杂度
本题总结
这道题代码简单,思维复杂。
让我明白了有些题是可以在草稿纸上算一算、写一写,找找规律的。
B:\texttt{dice}
初始思路
这题就读题有点困难,但理解之后十分简单。
我想着每个骰子都只有
解题过程
读题
考场代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int kN = 5;
int a[kN], b[kN], s[kN];
bool query(int x[], int y[]) {
int cnt1 = 0, cnt2 = 0;
for (int i = 1; i <= 4; i++)
for (int j = 1; j <= 4; j++)
if (x[i] > y[j])
cnt1++;
else if (y[j] > x[i])
cnt2++;
return cnt1 > cnt2;
}
void work() {
for (int i = 1; i <= 4; i++)
cin >> a[i];
for (int i = 1; i <= 4; i++)
cin >> b[i];
bool flag = 0;
for (int i = 1; i <= 10; i++)
for (int j = 1; j <= 10; j++)
for (int k = 1; k <= 10; k++) {
if (flag == 1) break;
for (int o = 1; o <= 10; o++) {
if (flag == 1) break;
s[1] = i, s[2] = j, s[3] = k, s[4] = o;
int cnta = query(a, b) + query(a, s);
int cntb = query(b, a) + query(b, s);
int cntc = query(s, a) + query(s, b);
if (cnta == 1 && cntb == 1 && cntc == 1) {
flag = 1;
}
}
}
if (flag == 1) cout << "yes\n";
else cout << "no\n";
}
signed main() {
freopen("dice.in", "r", stdin);
freopen("dice.out", "w", stdout);
int t;
cin >> t;
while (t--)
work();
return 0;
}
赛后题解
没有一点问题,见↑
补题代码
见上↑
时间复杂度
设
则时间复杂度为
本题总结
这道题十分简单,只要你搞清楚题意就行。
C:\texttt{herdle}
初始思路
先分别统计猜测矩阵和答案每个字母的个数,绿色高亮肯定就是判断是不是,黄色的话就是在两个矩阵的公共数量。
解题过程
读题
考场代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int kN = 5;
int ans1, ans2;
char a[kN][kN], b[kN][kN];
map<char, int> vis1, vis2;
signed main() {
freopen("herdle.in", "r", stdin);
freopen("herdle.out", "w", stdout);
for (int i = 1; i <= 3; i++)
for (int j = 1; j <= 3; j++) {
cin >> a[i][j];
vis1[a[i][j]]++;
}
for (int i = 1; i <= 3; i++)
for (int j = 1; j <= 3; j++) {
cin >> b[i][j];
if (a[i][j] == b[i][j]) {
ans1++;
vis1[a[i][j]]--;
vis2[a[i][j]]--;
}
vis2[b[i][j]]++;
}
for (char i = 'A'; i <= 'Z'; i++)
ans2 += min(vis1[i], vis2[i]);
cout << ans1 << "\n" << ans2;
return 0;
}
赛后题解
完全没有问题,见上↑
补题代码
见上↑
复杂度
设
则时间复杂度为
本题总结
提升了我的调试能力。
D:\texttt{fpot}
初始思路
这个时间差,说白了就是
然后我们要找最大值和最小值,用单调队列维护。
那怎么找花盆的宽度?
首先,暴力想都不用想,直接pass掉!
然后我想,是不是花盆越大越满足需求?那就不用说了,二分即可。
解题过程
读题
初始代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int kN = 1e5 + 5;
int n, d;
struct node {
int x, y;
} a[kN];
bool cmp(const node &x, const node &y) {
return x.x < y.x;
}
bool check(int x) {
deque<int> q, q2;
for (int i = 1; i <= n; i++) {
while (q.empty() == 0 && a[i].y > a[q.back()].y)
q.pop_back();
q.push_back(i);
while (a[i].x - a[q.front()].x > x)
q.pop_front();
while (q2.empty() == 0 && a[i].y < a[q2.back()].y)
q2.pop_back();
q2.push_back(i);
while (a[i].x - a[q2.front()].x > x)
q2.pop_front();
if (a[q.front()].y - a[q2.front()].y >= d)
return 1;
}
return 0;
}
signed main() {
freopen("fpot.in", "r", stdin);
freopen("fpot.out", "w", stdout);
cin >> n >> d;
for (int i = 1; i <= n; i++)
cin >> a[i].x >> a[i].y;
sort(a + 1, a + 1 + n, cmp);
int l = 0, r = 1e6 + 1;
while (l + 1 < r) {
int mid = (l + r) / 2;
if (check(mid) == 1) r = mid;
else l = mid;
}
cout << r;
return 0;
}
赛后题解
其实就跟我上面差不多,而我忘了一个东西——判
我无疑是非常的“高兴”好吧。话说怎么只有一个点是
当然,这题也可以用ST表。
补题代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int kN = 1e5 + 5;
int n, d;
struct node {
int x, y;
} a[kN];
bool cmp(const node &x, const node &y) {
return x.x < y.x;
}
bool check(int x) {
deque<int> q, q2;
for (int i = 1; i <= n; i++) {
while (q.empty() == 0 && a[i].y > a[q.back()].y)
q.pop_back();
q.push_back(i);
while (a[i].x - a[q.front()].x > x)
q.pop_front();
while (q2.empty() == 0 && a[i].y < a[q2.back()].y)
q2.pop_back();
q2.push_back(i);
while (a[i].x - a[q2.front()].x > x)
q2.pop_front();
if (a[q.front()].y - a[q2.front()].y >= d)
return 1;
}
return 0;
}
signed main() {
freopen("fpot.in", "r", stdin);
freopen("fpot.out", "w", stdout);
cin >> n >> d;
for (int i = 1; i <= n; i++)
cin >> a[i].x >> a[i].y;
sort(a + 1, a + 1 + n, cmp);
int l = 0, r = 1e6 + 1;
while (l + 1 < r) {
int mid = (l + r) / 2;
if (check(mid) == 1) r = mid;
else l = mid;
}
if (l == 1e6) cout << -1;
else cout << r;
return 0;
}
复杂度
设
则时间复杂度为
本题总结
让我知道了读题很重要。 。 。
整体反思
做的较好的地方
基本后面
需要改进的地方
我检查的不够到位。(摔键盘)
时间安排总结
其实挺好的,虽然有点“偏心”(?