Card Scoring
这题当 \(k = 3\) 时还无法解决,但是 \(k = 2\) 与 \(k = 4\),\(k = 2\)时可以直接用前缀和和 \(dp\) 解决,而 \(k = 4\) 时可以用李超线段树
Marshmallow Molecules
这题直接启发式合并
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 5;
int n, m, ans;
set<int> s[N];
signed main() {
cin >> n >> m;
for (int i = 1, u, v; i <= m; i++) {
cin >> u >> v;
s[u].insert(v);
}
for (int i = 1; i <= n; i++) {
if (!s[i].size()) {
continue;
}
ans += s[i].size();
int x = *s[i].begin();
s[i].erase(s[i].begin());
if (s[i].size() > s[x].size()) {
swap(s[i], s[x]);
}
while (!s[i].empty()) {
s[x].insert(*s[i].begin());
s[i].erase(s[i].begin());
}
}
cout << ans;
return 0;
}
然\
标签:insert,20240918,int,begin,long,这题 From: https://www.cnblogs.com/libohan/p/18444286