题意 & 题解
A Don't be late
题意:给你路程,时间限制,速度,问你能不能在时间限制内走路程那么远。
题解:数学题?物理题?
B Substring
题意:给你两个字符串 \(s,t\),问你最少更改 \(s\) 几次能使得 \(t\) 是 \(s\) 的字串。
题解:因为字符串长度小于 \(1000\) 直接暴力枚举 \(t\) 出现在 \(s\) 的什么位置。
C Sum of product of pairs
题意:求 \(\sum\limits_{i = 1}^{N - 1}\sum\limits_{j = i + 1} ^ {N} A_i A_j\)
题解:数学题,化简一下就成了 \(\sum\limits_{i = 1}^{N - 1}A_i\sum\limits_{j = i + 1} ^ {N} A_j\),后面用前缀和维护一下就好。
D Friends
题意:给你一些人之间的朋友关系,可以互相传递,问你最少分成多少组使得每一组都没有两个人是朋友。
题解:并查集。最大的连通块的大小就是答案,应该挺显然的。
E Coprime
题意:咕咕咕
题解:咕咕咕
F I hate Shortest Path Problem
题意:咕咕咕
题解:咕咕咕
Code
A Don't be late
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
int a, b, c;
int main() {
std::cin >> a >> b >> c;
double t = (a * 1.0) / (c * 1.0);
if (t - b * 1.0 >= 1e-8) puts("No");
else puts("Yes");
return 0;
}
B Substring
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
int min(int a, int b) { return a < b ? a : b; }
int ans = 2147483647;
std::string s, t;
int main() {
std::cin >> s >> t;
int len1 = s.length(), len2 = t.length();
for (int i = 0; i < len1; ++i) {
if (i + len2 - 1 >= len1) break;
int p = i, sum = 0;
for (int j = 0; j < len2; ++j, ++p) {
if (s[p] == t[j]) ++sum;
}
ans = min(ans, len2 - sum);
}
std::cout << ans << '\n';
return 0;
}
C Sum of product of pairs
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#define MAXN 200001
#define int long long
const int mod = 1000000007;
int n, ans, a[MAXN], sum[MAXN];
signed main() {
scanf("%lld", &n);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &a[i]);
sum[i] = (1ll * sum[i - 1] + 1ll * a[i]) % mod;
}
for (int i = 1; i < n; ++i) {
ans = (ans + 1ll * a[i] * ((sum[n] - sum[i] + mod) % mod) % mod) % mod;
}
std::cout << ans << '\n';
return 0;
}
D Friends
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#define MAXN 200001
int max(int a, int b) { return a > b ? a : b; }
int n, m, fa[MAXN], size[MAXN];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void Union(int x, int y) {
int rootx = find(x), rooty = find(y);
if (rootx == rooty) return;
if (size[rootx] > size[rooty]) {
fa[rooty] = rootx;
size[rootx] += size[rooty];
}
else {
fa[rootx] = rooty;
size[rooty] += size[rootx];
}
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; ++i) fa[i] = i, size[i] = 1;
for (int i = 1, u, v; i <= m; ++i) {
scanf("%d %d", &u, &v);
Union(u, v);
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
if (fa[i] == i) ans = max(ans, size[i]);
}
std::cout << ans << '\n';
return 0;
}
rating & 总结
- C题取模因为负数的原因WA了两发/kk
- D题因为最后统计答案的时候把 n 写成了 m (什么sb)WA了一发。
- EF都没思路,真是个垃圾。