2025年8月15日模拟测总结
Situation
| 题目名称 | bookshelf | tractor | operations | |
|---|---|---|---|---|
| 预计得分 | 100 | 0 | 0 | 0 |
| 实际得分 | 100 | 10 | 9 | 0 |
Total score:119 points Rank:28th
Method
A 书架 bookshelf
—— Only know this question
Idea
突破口在于放入书架的顺序不变,那么我们可以求出每个区间的 最大高度 和 宽度总和 ,
然后去 DP 放置方案,定义 表示考虑前 本书时,书架的最小高度。
My approach
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;
const int N = 2005;
int n, L, h[N], w[N];
llong f[N][N], v[N][N], g[N];
int main() {
freopen("bookshelf.in", "r", stdin);
freopen("bookshelf.out", "w", stdout);
scanf("%d%d", &n, &L);
for (int i = 1; i <= n; i++)
scanf("%d%d", &h[i], &w[i]);
for (int d = 0; d < n; d++)
for (int i = 1; i + d <= n; i++) {
int j = i + d;
if (i == j) {
f[i][j] = w[j];
v[i][j] = h[j];
}
else {
f[i][j] = f[i][j - 1] + w[j];
v[i][j] = max(v[i][j - 1], 1LL * h[j]);
}
}
g[0] = 0;
for (int i = 1; i <= n; i++) {
g[i] = 1LL << 55LL;
for (int j = 1; j <= i; j++)
if (f[j][i] <= L)
g[i] = min(g[i], g[j - 1] + v[j][i]);
}
printf("%lld\n", g[n]);
return 0;
} Score
100 points
Cause of losing points
这是这场唯一AC了的题
B 拖拉机 tractor
—— Brain cramp
Idea
二分一下答案就行了,check 用 DFS 搜 连通块 。
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;
const int d[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
const int N = 505;
int n, k, a[N][N], tot;
bool vis[N][N];
void sous(int x, int y, int z) {
vis[x][y] = true; tot++;
for (int i = 0; i < 4; i++) {
int xx = x + d[i][0], yy = y + d[i][1];
if (xx < 1 || xx > n || yy < 1 || yy > n) continue;
if (!vis[xx][yy] && abs(a[x][y] - a[xx][yy]) <= z)
sous(xx, yy, z);
}
}
bool check(int z) {
memset(vis, false, sizeof(vis));
for (int x = 1; x <= n; x++)
for (int y = 1; y <= n; y++)
if (!vis[x][y]) {
tot = 0;
sous(x, y, z);
if (tot >= k)
return true;
}
return false;
}
int main() {
freopen("tractor.in", "r", stdin);
freopen("tractor.out", "w", stdout);
scanf("%d", &n);
k = (n * n + 1) / 2;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
scanf("%d", &a[i][j]);
int L = 0, R = 1000000;
while (L + 1 < R) {
int M = (L + R) / 2;
if (check(M))
R = M;
else
L = M;
}
printf("%d\n", R);
return 0;
}My approach
先用 DFS 把相同高度的联通块搜出来作为一个点,数量作为点权,然后把相邻的联通块在对应的点上连边,边权为高度之差,然后用 Kruskal 找到这个图的 最小生成树MST 。然后,然后就不会做了。。。
Score
10 points
Cause of losing points
脑抽
C 邮件归档 mail
—— Simulation
Idea
用STL模拟一下
My approach
不会
Score
9 points
Cause of losing points
太菜了
D COW操作 operations
—— Find the pattern
Idea
区间内 O 和 W 数量的差为 偶数 ,且转成 C 后的总数是 奇数,就是可行的。
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
char s[N];
int n, q, a[3][N];
int main() {
freopen("operations.in", "r", stdin);
freopen("operations.out", "w", stdout);
scanf("%s%d", s + 1, &q);
n = strlen(s + 1);
a[0][0] = a[1][0] = a[2][0] = 0;
for (int i = 1; i <= n; i++) {
a[0][i] = a[0][i - 1];
a[1][i] = a[1][i - 1];
a[2][i] = a[2][i - 1];
if (s[i] == 'C')
a[0][i]++;
else if (s[i] == 'O')
a[1][i]++;
else if (s[i] == 'W')
a[2][i]++;
}
while (q--) {
int l, r;
scanf("%d%d", &l, &r);
if (abs((a[1][r] - a[1][l - 1]) - (a[2][r] - a[2][l - 1])) % 2 == 0 && (min(a[1][r] - a[1][l - 1], a[2][r] - a[2][l - 1]) + a[0][r] - a[0][l - 1]) % 2 == 1)
printf("Y");
else
printf("N");
}
return 0;
}My approach
不会
Score
0 points
Cause of losing points
心态崩了
Summarize
怎么分又低了 TAT
Reflections
稻花香里说丰年,听取声一片。