AtCoder Beginner Contest 224(A-F)
知识点整理:
| 题号 | 知识点 | 备注 |
|---|---|---|
| A | 无 | |
| B | 无 | |
| C | 图 | |
| D | 基础DP | 矩阵最大路径和变种 |
| E | 状态机DP | |
| F | 状压DP | |
| G | ? | |
| H | ? |
A - QQ solver
题意
给你三个字符组成的乘法表达式, 求计算结果
题解
用scanf读入整数
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
scanf("%dx%d", &a, &b);
printf("%d\n", a*b);return 0;
}
B - Caesar Cipher
题意
给定两个字符串AAA和BBB, 问能否通过字母的轮换把A变成B
题解
一共就26种情况, 暴力枚举, 需注意char的最大范围是128, 有可能溢出.
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
bool flag = false;
for (int i = 0; i < 26; i++) {
string c = a;
for (int j = 0; j < c.size(); j++) {
c[j] = (char)(a[j] + i);
if (c[j] > 'z' || c[j] < 0) {
c[j] = (char) (a[j] - 26 + i);
}
}
if (c == b) {
flag = true;
break;
}
}
puts(flag ? "Yes" : "No");
return 0;
}
C - Graph Isomorphism
题意
两个图是否同构
题解
8个点, 一共就8!种情况, 暴力枚举
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int a[N][N];
int b[N][N];
struct node {
int x, y;
} c[N];
int n, m;
int vis[N];
int res[9] = {
0, 1, 2, 3, 4, 5, 6, 7, 8};
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
a[x][y] = 1;
a[y][x] = 1;
c[i] = {
x, y};
}
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
b[x][y] = 1;
b[y][x] = 1;
}
bool flag = 0;
int cnt = 0;
int dex = 1;
for (int i = 1; i <= m; i++) {
if (b[res[c[i].x]][res[c[i].y]] == 0 &&
b[res[c[i].y]][res[c[i].x]] == 0) {
dex = 0;
break;
}
}
if(dex==1) {
puts("Yes");
return 0;
}
while (next_permutation(res + 1, res + n + 1)) {
int now = 1;
for (int i = 1; i <= m; i++) {
if (b[res[c[i].x]][res[c[i].y]] == 0 &&
b[res[c[i].y]][res[c[i].x]] == 0) {
now = 0;
break;
}
}
if (now == 1) {
flag = 1;
break;
}
}
if (flag)

最低0.47元/天 解锁文章
4443





