2025年8月1日模拟测总结
Situation
| 题目名称 | mooomoo | auto | fairphoto | gpsduel |
|---|---|---|---|---|
| 预计得分 | 100 | 100 | 33 | 0 |
| 实际得分 | 100 | 100 | 60 | 10 |
Total score:270 points Rank:11th
第2题原来测出是60分,重测后100分
Method
A Mooo Moo mooomoo
—— Will it TLE?
Idea
既然每个牧场的总音量都给定了,为何不去还原每个牧场本身的音量呢?将还原出来的第 个牧场的音量记作 ,那么要去考虑每个 能由哪些 相加而成,这就变成完全背包问题了!
时间复杂度:
My approach
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;
const int inf = 1 << 30;
const int N = 105;
const int V = 100005;
int n, m, k, v[N], a[N], f[V];
int main() {
freopen("mooomoo.in", "r", stdin);
freopen("mooomoo.out", "w", stdout);
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++)
scanf("%d", &v[i]);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = n; i >= 2; i--) {
a[i] -= max(a[i - 1] - 1, 0);
if (a[i] < 0) {
printf("-1\n");
return 0;
}
}
llong ans = 0;
for (int p = 1; p <= n; p++) {
memset(f, 127, sizeof(f));
f[0] = 0;
for (int i = 1; i <= m; i++)
for (int j = v[i]; j <= a[p]; j++)
f[j] = min(f[j], f[j - v[i]] + 1);
if (f[a[p]] > inf) {
printf("-1\n");
return 0;
}
ans += f[a[p]];
}
printf("%lld\n", ans);
return 0;
}Score
100 points
Cause of losing points
嗯。。。这栏有意义吗
B 自动补全 auto
—— I’m really awesome
Idea
将字符串按字典序排序后二分。
My approach
有“亿点”复杂,将字符串都存到一个字典树Trie里,然后对这棵字典树进行DFS,抠出其中所有字符串结尾落到的节点,再把这些节点构出一棵树。找到查询字符串结尾的节点,向下DFS找到对应字典序第 小的字符串。
时间复杂度:
#include <bits/stdc++.h>
using namespace std;
const int M = 50000;
const int L = 1000005;
int m, n, k[1005], nxt[L][26], isend[L], r[M], pos[M], duiy[M], sum[M], cnt = 0, tot = 0, zongh = 0;
vector<int> edges[M], hvend[L];
char s[L];
void dfs(int p, int fa) {
if (isend[p] || !hvend[p].empty()) {
tot++;
edges[fa].push_back(tot);
if (isend[p]) {
pos[isend[p]] = tot;
r[tot] = isend[p];
}
if (!hvend[p].empty())
for (auto i : hvend[p]) {
pos[i + m] = tot;
}
duiy[tot] = p;
}
int father = fa;
if (isend[p] || !hvend[p].empty())
father = tot;
for (int i = 0; i < 26; i++)
if (nxt[p][i])
dfs(nxt[p][i], father);
}
void DFS(int p) {
sum[p] = 0;
if (isend[duiy[p]])
sum[p] = 1;
for (auto i : edges[p]) {
DFS(i);
sum[p] += sum[i];
}
}
int search(int p, int cnt) {
if (isend[duiy[p]]) {
if (cnt == 1)
return r[p];
cnt--;
}
int tot = 0;
for (auto i : edges[p]) {
if (tot + sum[i] >= cnt)
return search(i, cnt - tot);
tot += sum[i];
}
return -1;
}
int main() {
freopen("auto.in", "r", stdin);
freopen("auto.out", "w", stdout);
scanf("%d%d", &m, &n);
for (int i = 1; i <= m; i++) {
scanf("%s", s + 1);
int len = strlen(s + 1), p = 0;
for (int i = 1; i <= len; i++) {
int x = s[i] - 'a';
if (!nxt[p][x]) nxt[p][x] = ++cnt;
p = nxt[p][x];
}
isend[p] = i;
}
for (int i = 1; i <= n; i++) {
scanf("%d%s", &k[i], s + 1);
int len = strlen(s + 1), p = 0;
for (int i = 1; i <= len; i++) {
int x = s[i] - 'a';
if (!nxt[p][x]) nxt[p][x] = ++cnt;
p = nxt[p][x];
}
hvend[p].push_back(i);
}
dfs(0, 0);
DFS(0);
for (int i = 1; i <= n; i++)
printf("%d\n", search(pos[m + i], k[i]));
return 0;
}Score
100 points
原来测出是60分
Cause of losing points
就讲一下为什么原来测是60分吧,因为题目里说 ,实际上 。
C 公平拍照 fairphoto
—— A blue problem
Idea
设W的权值为-1,S的权值为1,将数组排序后对权值进行前缀和,满足以下条件的区间 是可选的
My approach
将数组排序后暴力 枚举两个端点,保证 ,用前缀和优化区间查询,只要区间内的纯白牛数量不少于斑点牛数量,就是可行的方案,然后取长度的最大值。
Score
60 points
Cause of losing points
只会暴力。。。
D 冲突的GPS gpsduel
—— No enough time
Idea
由于每走一步“到 号顶点的距离”就会发生改变,所以我们应该要把两个GPS想象图的反图进行从 号顶点为起点的Dijkstra,对于一条边,在这两个图中要是没经过就会被喷,以被喷的次数为边权再建一个图,再跑一遍Dijkstra就行了!
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;
const int N = 10001;
struct Edge {
int u, v, w, x;
} edge[50001];
int n, m;
vector<pair<int, int>> edges[3][N];
llong dist[3][N];
set<pair<llong, int>> s;
void dijkstra(int t, int start) {
memset(dist[t], 127, sizeof(dist[t]));
dist[t][start] = 0;
s.clear();
for (int i = 1; i <= n; i++)
s.insert({dist[t][i], i});
while (!s.empty()) {
int x = s.begin() -> second;
s.erase(s.begin());
for (auto i : edges[t][x])
if (dist[t][x] + i.second < dist[t][i.first]) {
s.erase({dist[t][i.first], i.first});
dist[t][i.first] = dist[t][x] + i.second;
s.insert({dist[t][i.first], i.first});
}
}
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int u, v, w, x;
scanf("%d%d%d%d", &u, &v, &w, &x);
edge[i] = {u, v, w, x};
edges[0][v].push_back({u, w});
edges[1][v].push_back({u, x});
}
dijkstra(0, n);
dijkstra(1, n);
for (int i = 1; i <= m; i++) {
int u = edge[i].u, v = edge[i].v, w = 0;
if (dist[0][v] + edge[i].w != dist[0][u])
w++;
if (dist[1][v] + edge[i].x != dist[1][u])
w++;
edges[2][u].push_back({v, w});
}
dijkstra(2, 1);
printf("%lld\n", dist[2][n]);
return 0;
}My approach
赛时想写“先Dijkstra再DFS每条边选或不选”的暴力方法,但是没时间了,想想还是算了吧,直接输出 。。。
Score
10 points
Cause of losing points
没时间了,如果还有时间的话。。。
Summarize
菜就多练
Reflections
稻花香里说丰年,听取WA声一片!