比赛链接:​​https://atcoder.jp/contests/abc049​

A - UOIAUAI

题目大意:
判断一个字符是不是元音字母。

示例程序:

#include <bits/stdc++.h>
using namespace std;
int main() {
char c = getchar();
puts( c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ? "vowel" : "consonant" );
return 0;
}

B - Thin

题目大意:
每个字符串输出两遍。

示例程序:

#include <bits/stdc++.h>
using namespace std;
int n, m;
string s;
int main() {
cin >> n >> m;
while (n --) {
cin >> s;
cout << s << endl << s << endl;
}
return 0;
}

C - Daydream

题目大意:
给你一个字符串,请你判断这个字符串能否由若干个 "dream"、"dreamer"、"erase"、"eraser" 中的其中一个字符串拼接而成。

解题思路:

模拟。正着判断可能会遇到 "dreamer..." 但是不知道该 "dream" 还是 "dreamer" 的情况。但是 倒着来 刚好可以解决这个问题。所以倒着遍历一遍即可。

示例程序:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
char s[maxn];
bool f[maxn];
int main() {
cin >> s+1;
int i = strlen(s+1);
while (i > 0) {
if (i >= 5 && strncmp(s+i-4, "dream", 5) == 0) i -= 5;
else if (i >= 7 && strncmp(s+i-6, "dreamer", 7) == 0) i -= 7;
else if (i >= 5 && strncmp(s+i-4, "erase", 5) == 0) i -= 5;
else if (i >= 6 && strncmp(s+i-5, "eraser", 6) == 0) i -= 6;
else {
puts("NO");
return 0;
}
}
puts("YES");
return 0;
}

D - Connectivity

题目大意:
给你 \(N\) 个城市,\(K\) 条公路,\(L\) 条铁路。你需要回答出任意一个城市,有多少城市和它公路连通,有多少城市和它铁路连通。

解题思路:
维护两个并查集即可。然后对所有点在两个并查集中的祖先id(一对整数)做 hash 存到 map 中,map 记录 hash 值出现的次数。因为在在两个并查集中都属于连通块的两个点的 hash 值也相同。

示例程序:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 200020;
long long h(int a, int b) {
return (long long) a * maxn + b;
}
map<long long, int> mp;
struct Node {
int n, f[maxn];
void init() {
for (int i = 1; i <= n; i ++) f[i] = i;
}
int Find(int x) {
return x == f[x] ? x : f[x] = Find(f[x]);
}
void Union(int x, int y) {
int a = Find(x), b = Find(y);
f[a] = f[b] = f[x] = f[y] = min(a, b);
}
} G1, G2;
int n, K, L;
int main() {
cin >> n >> K >> L;
G1.n = G2.n = n;
G1.init(), G2.init();
while (K --) {
int a, b;
cin >> a >> b;
G1.Union(a, b);
}
while (L --) {
int a, b;
cin >> a >> b;
G2.Union(a, b);
}
for (int i = 1; i <= n; i ++) {
int a = G1.Find(i), b = G2.Find(i);
mp[h(a, b)] ++;
}
for (int i = 1; i <= n; i ++) {
int a = G1.Find(i), b = G2.Find(i);
cout << mp[h(a, b)] << " ";
}
return 0;
}