Day 6
Day 6
早上
早饭就俩面包和一杯咖啡.
lzy 吃了那个神秘凉糕后露出了痛苦面具.
没绷住.
咖啡没喝完可惜了.
上午测试
没啥好说的吧.
T1 看了眼没啥思路, 然后写了个 A* 就跑路看 T2 了.
被期望卡了半天, 然后突然发现 lzy 在写 T2 的 DP 不知道为什么突然想到 T1 的 DP 就切了.
T1
给你一个序列, 一次操作可以删除一个数字或者让一个数字加一, 问至少多少次操作能在模 \(m\) 的意义下等于 \(0\)
\(f_i\) 表示和的模数为 \(i\) .
#include <bits/stdc++.h>
using namespace std;
namespace OI {
#define int long long
#define endl "\n"
constexpr int maxn = 1005;
int n, mod;
int a[maxn], f[maxn], g[maxn];
void main() {
cin >> n >> mod;
int sum = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] %= mod;
sum = (sum + a[i]) % mod;
}
sort(a + 1, a + 1 + n);
for (int i = 0; i < mod; i++)
f[i] = LONG_LONG_MAX >> 1;
f[sum] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < mod; j++)
g[j] = f[j];
for (int j = 0; j < mod; j++) {
f[j] = min(f[j], g[(j + a[i]) % mod] + 1);
}
}
int ans = f[0];
for (int i = 1; i < mod; i++)
ans = min(ans, f[i] + mod - i);
cout << ans << endl;
}
#undef int
#undef endl
}
int main() {
freopen("player.in", "r", stdin);
freopen("player.out", "w", stdout);
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(0);
OI::main();
return 0;
}
注意滚动数组要开俩.
然后就没什么切的了, T2 不会.
考试考一半发现鞋坏了(?)咋坏的啊.
T3 打了个暴力然后曼哈顿距离写挂了.(?)不像人类.
T4 想到了 \(\mathcal{O}(n^2)\) 的树 DP 然后犯糖写挂了.
并且想到是长链剖分优化 DP 但是没来得及写.
好的.
中午
哇塞喜嘉德有个牛肉蔬菜锅真的好吃.
中午的时候讲解字符串的老师非常之活跃啊, 还是清华羟基第一的大佬!
在说关于 zhy 和 gzy 的事。
欣赏我的美妙动态壁纸!

下午
大抵是在颓.
T4
给你一棵白色的树, 每次操作可以消耗 \(a_k\) 的代价在一个子树的第 \(k\) 层涂色为黑色.
很显然暴力 DP 是显然的, 只要发现分层性质就好.
不知道为啥我赛时犯糖写成 \(\mathcal{O}(n^4)\) 了.
#include <bits/stdc++.h>
using namespace std;
namespace OI {
#define int long long
#define endl "\n"
constexpr int maxn = 1e5+5;
int a[maxn];
int n;
vector<int> graph[maxn];
int f[maxn][maxn];
void dfs(int u, int fa) {
for (int v : graph[u]) {
if (v == fa)
continue;
dfs(v, u);
for (int k = 1; k < n; k++)
f[u][k] += f[v][k - 1];
}
f[u][0] = a[0];
for (int k = 1; k < n; k++)
f[u][k] = min(f[u][k], a[k]);
}
void main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
graph[u].push_back(v),
graph[v].push_back(u);
}
dfs(1, 0);
int ans = 0;
for (int k = 0; k < n; k++)
ans += f[1][k];
cout << ans << endl;
}
#undef int
#undef endl
}
int main() {
freopen("wisdom.in", "r", stdin);
freopen("wisdom.out", "w", stdout);
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(0);
OI::main();
return 0;
}
// O(n^2)
然后一直在和 h3z 新生瞎扯淡.
h3z 规则怪谈
- \(\textcolor{red}{课间不要大声喧哗、吵闹,否则会接受【制裁】}\)
- \(\textcolor{red}{不要在语文课上吃东西,否则你的双腿会牵引你去往【前方】}\)
- \(\textcolor{red}{请不要在生物课上进行自由交配}\)
- \(\textcolor{red}{请不要在数学课上睡觉,否则你的双腿会僵直}\)
- \(\textcolor{red}{当你接受【制裁】时,请不要逃跑}\)
- 一定要尽全力赶往食堂,否则不要前往
- 小卖部是安全的
- 在 Q 吃完饭一定要倒餐盘
- 如果你处于 Q,请不要在 A 区上厕所,否则会被处决
- 红色规则作废
- \(\textcolor{red}{上一条规则作废}\)
- \(\textcolor{red}{值日值日值日值日值日值日值日值日值日}\)
字符串 T2
看着 T2 是简单题.
(不是原题目背景)
给你一个基因序列, 每次迭代会复制上一代的基因. 在这个过程中可能会发生变异, 导致 \(s'_i = s'_{i - 1}\)
求至少要多少代才能让 \(s\) 进化成 \(t\) .
很显然的贪心, 用双指针乱搞一下就好了.
#include <bits/stdc++.h>
using namespace std;
namespace OI {
#define int long long
#define endl "\n"
int n;
string s, t;
queue<int> q;
void main() {
cin >> n;
cin >> s >> t;
if (s == t) {
cout << 0 << endl;
return;
}
s = ' ' + s, t = ' ' + t;
int up = n;
int down = n;
int ans = 0;
while (down >= 1) {
while (down > 1 && t[down - 1] == t[down])
--down;
while (up >= 1 && (up > down || s[up] != t[down]))
--up;
if (up < 1) {
cout << -1 << endl;
return;
}
while (!q.empty() && q.front() - (int)q.size() >= down)
q.pop();
if (up != down)
q.push(up);
ans = max(ans, (int)q.size() + 1);
--down;
}
cout << ans << endl;
}
#undef int
#undef endl
}
int main() {
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(0);
OI::main();
return 0;
}
这剩下的字符串题我是真的不想写.
晚上
回去的时候感觉嗓子有点疼, 当时有点渴了.
我再玩三国杀我是狗
狗卡控牌堆啊.
然后就是疯狂的打麻将.
依旧疯狂吃 Rank -1.
中间吃了口披萨, 进行了激烈的小说讨论.
然后接着打麻将. 到半夜十一点半, 把把 Rank -1, 神了.

浙公网安备 33010602011771号