Day 8
Day 8
早上
一杯橙汁, 两个面包片 + 黄油.
上午
神秘模拟赛.
T1 想了半天, 一开始想的是 Tarjan 做法, 后来发现假了又发明了 \(\mathcal{O}(nm)\) 的找所有环算法.
emm T1 炸了.
然后看 T2 交互, 想了半天啥也没想出来, 打了个暴力结果没交, 交了个不如暴力的玩意.
神的来了, 我不小心按到了键盘上的 F12 导致我的电脑打开了声音, 而且我的动态壁纸其实是有声音的.
然后机房中响起了一首强劲的音乐:
噔噔噔瞪~ 噔噔噔, 噔~ 噔噔噔, 噔噔噔噔, 噔噔噔噔, 噔噔噔~
噔噔噔噔~
||断了乱了 + 九万字的三国杀进行曲||
这期真神了.
然后 lzy 一脚给我电源踹了, 电脑关机了.
神了.
中午
吃了碗羊杂面.
下午
先改题.
T1
给你一个图, 有黑边和白边, 每次操作可以把一个有白边的简单环染成黑色, 求最大操作次数.
每次操作相当于把两个黑色的连通块连接起来, 那么可以用 DSU 维护黑色连通块, 最终答案是白色边数 - 黑色块数 + 1.
#include <bits/stdc++.h>
using namespace std;
namespace OI {
#define int long long
#define endl "\n"
constexpr int maxn = 2e5+5;
int T, n, m;
int f[maxn];
int find(int x) {
if (f[x] == x)
return x;
return f[x] = find(f[x]);
}
void main() {
cin >> T;
while (T--) {
cin >> n >> m;
for (int i = 1; i <= n; i++)
f[i] = i;
int white = 0;
for (int i = 1; i <= m; i++) {
int u, v, w;
cin >> u >> v >> w;
if (w)
f[find(v)] = find(u);
else
white++;
}
int black = 0;
for (int i = 1; i <= n; i++)
f[i] = find(i);
unordered_set<int> stat(f + 1, f + 1 + n);
black = stat.size();
cout << white - black + 1 << endl;
}
}
#undef int
#undef endl
}
int main() {
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(0);
OI::main();
return 0;
}
T2
交互题, 由若干个位置地点的电梯, 每次你按电梯可以让最近的电梯过来并告诉你是哪个电梯, 最终求每个电梯的位置, 限 \(2n - 1\) 次查询.
先查询 \(L = 1\) 并定查询 \(R = L + 2^{\lfloor\log_2 m - L\rfloor}\)
对于区间 \((l, r)\) 查询 \(mid\) 的状态, 如果有见过的电梯出现我们视为区间已查询完毕, 否则继续查询 \((l, mid), (mid, r)\)
结束后 \(L = R\) 并继续.
可以证明有至多 \(n\) 次可用和 \(2n - 1\) 次无用信息.
#include <bits/stdc++.h>
using namespace std;
namespace OI {
#define int long long
const int maxn = 2200;
int c, T, n, m;
int ans[maxn];
int cnt;
int query(int pos) {
cout << "press " << pos << endl;
int ret;
cin >> ret;
return ret;
}
void dfs(int l, int r) {
if (cnt == 0)
return;
if (r - l <= 1)
return;
int mid = l + r >> 1;
int res = query(mid);
if (ans[res] != -1) {
ans[res] = mid;
return;
}
ans[res] = mid;
if (!(--cnt))
return;
dfs(l, mid),
dfs(mid, r);
}
int logPow(int x) {
int p = 1;
while (p * 2 <= x)
p <<= 1;
return p;
}
void solve() {
cin >> n >> m;
if (n == 1) {
int x = query(1);
cout << "answer 1" << endl;
return;
}
memset(ans, -1, sizeof(ans));
cnt = n;
int res1 = query(1);
if (ans[res1] == -1)
cnt--;
ans[res1] = 1;
int L = 1, R = 1;
while (cnt > 0) {
L = R;
R = L + logPow(m - L);
if (R > m)
R = m;
int resR = query(R);
if (ans[resR] == -1)
cnt--;
ans[resR] = R;
dfs(L, R);
}
cout << "answer";
for (int i = 1; i <= n; i++)
cout << " " << ans[i];
cout << endl;
}
void main() {
cin >> c >> T;
while (T--) {
solve();
}
}
#undef int
}
int main() {
OI::main();
return 0;
}
晚上休息
没有吃饭, 去听 lzy 弹琴.
「诀别书」
或许有人退役的时候会用到.
买了个鱿鱼游戏的饼干和马卡龙.
晚自习
那个饼干不好吃, 马卡龙也不好吃.
哦马卡龙只能说一般.
手滑又把声音打开了.
制作了极品头像.




似乎有点感冒了.
晚上
emm 好像就是看剧然后睡觉.
啥也没干啊.

浙公网安备 33010602011771号