我解决的:E(1 WA)、F、I、A。
没看的:H。
旁观的:C、G、D。
看了但没做出来的:K、B、J。
E Expeditious Cubing
简单题,略。
C Canvas Line
看起来是一个不很难的贪心,略。
F Firetrucks Are Red
题意:有 n n n 个点,每个点有一个数集。两个点的数集有非空交集则两个点可以以该数为权,连一条边。求一个生成树。
枚举数,将具有相同数的点连起来即可,要用并查集维护连通性。
#include <bits/stdc++.h>
using namespace std;
unordered_map<int, int> mp;
int tot, lst[200005];
int to[200005], nxt[200005], at[200005] = {
0}, cnt = 0;
int ans[200005][3];
int fa[200005], siz[200005];
int Find(int x){
return (x == fa[x] ? x: (fa[x] = Find(fa[x])));
}
int Union(int u, int v){
u = Find(u), v = Find(v);
if (u == v) return 0;
if (siz[u] > siz[v]) fa[v] = u, siz[u] += siz[v];
else fa[u] = v, siz[v] += siz[u];
return 1;
}
int main(){
int n;
scanf("%d", &n);
tot = 0;
for (int i = 1; i <= n; ++i){
int t, num;
scanf("%d", &t);
for (int j = 1; j <= t; ++j){
scanf("%d", &num);
if (!mp.count(num)) {
mp[num] = ++tot;
lst[tot] = num;
}
int id = mp[num];
to[++cnt] = i, nxt[cnt] = at[id], at[id] = cnt;
}
}
for (int i = 1; i <= n; ++i)
fa[i] = i, siz[i] = 1;
int res = 0;
for (int i = 1; i <= tot; ++i){
if (!at[i]) continue;
int rep = to[at[i]];
for (int j = at[i]; j; j = nxt[j]){
if (Union(to[j], rep)){
ans[++res][0] = to[j],
ans[res][1] = rep,
ans[res][2] = lst[i];
}
}
}
if (res < n - 1) {
printf("impossible\n");
}else {
for (int i = 1; i <= res; ++i){
printf("%d %d %d\n", ans[i][0], ans[i][1], ans[i][2]);
}
}
return 0;
}
I Inverted Deck
题意:给定一个序列,问能否反转一个连续子序列使得序列不降。
先把相同的数缩成一个,使得序列中没有相邻的相同数。设序列为 a a a,从头开始,第一个不满足 a i ≤ a i + 1 a_i \le a_{i+1} ai≤