我是靠谱客的博主 魁梧电话,这篇文章主要介绍第十届蓝桥杯C++B组题解,现在分享给大家,希望可以做个参考。

国赛题确实不简单哇hhh

前6题没有太大难度。第7题DP分类讨论实在是太多了,完全可以当压轴来出了呜呜呜,第8题运气好的话还是能做出来的hhh,这种题往往都不难都是找规律。第9题线段树的运用,但是很暴力很暴力,也算是一个积累叭。第10题直接暴力搜惹。希望今年国赛能做出来8道题就已经非常非常非常满足惹

A 平方序列

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream> #include <cstring> #include <algorithm> #include <cmath> using namespace std; int main() { int x, y; for (int i = 2020; i; i ++ ) { x = i; int t = 2 * x * x - 2019 * 2019; y = sqrt(t); if (y * y == t) break; } cout << x + y << endl; return 0; }

B 质数拆分

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <vector> using namespace std; const int N = 2022; typedef long long LL; vector<int> res; LL f[N]; bool is_prime(int x) // 判定质数 { if (x < 2) return false; for (int i = 2; i <= x / i; i ++ ) if (x % i == 0) return false; return true; } int main() { for (int i = 2; i <= 2019; i ++ ) if (is_prime(i)) res.push_back(i); f[0] = 1; for (int i = 0; i < res.size(); i ++ ) { for (int j = 2019; j >= res[i]; j -- ) f[j] += f[j - res[i]]; } cout << f[2019] << endl; return 0; }

C 拼接

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 10; bool st[N][N]; int n = 7, ans; int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; void dfs(int x, int y) { if (x == 0 || y == 7) { ans ++ ; return; } for (int i = 0; i < 4; i ++ ) { int a = x + dx[i], b = y + dy[i]; if (a < 0 || a > n || b < 0 || b > n) continue; if (st[a][b] || a == b) continue; st[a][b] = st[b][a] = true; dfs(a, b); st[a][b] = st[b][a] = false; } } int main() { for (int i = 0; i <= n; i ++ ) { st[i][i] = true; dfs(i, i); st[i][i] = false; } cout << ans << endl; return 0; }

D 求值

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream> #include <cstring> #include <algorithm> using namespace std; int count(int x) { int cnt = 1; for (int i = 2; i <= x / i; i ++ ) { int s = 0; while (x % i == 0) { x /= i; s ++ ; } cnt *= 1 + s; } if (x > 1) cnt *= 2; return cnt; } int main() { for (int i = 100; i; i ++ ) { if (count(i) == 100) { cout << i << endl; break; } } return 0; }

E 路径计数

这道题官网答案有误,比赛时是按照206这个答案几分的

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream> #include <cstring> #include <algorithm> typedef long long LL; using namespace std; const int N = 10; LL ans; bool st[N][N]; int n = 6; int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; bool check(int x) { return x > 1 && x <= 11; } void dfs(int x, int y, int step) { if (x == 0 && y == 0 && check(step)) { ans ++ ; return ; } st[x][y] = true; for (int i = 0; i < 4; i ++ ) { int a = x + dx[i], b = y + dy[i]; if (a < 0 || a >= n || b < 0 || b >= n) continue; if (st[a][b]) continue; dfs(a, b, step + 1); } st[x][y] = false; } int main() { dfs(0, 1, 0); cout << ans * 2 << endl; return 0; }

F 最优包含

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 1010; char a[N], b[N]; int f[N][N]; int main() { scanf("%s%s", a + 1, b + 1); int n = strlen(a + 1), m = strlen(b + 1); memset(f, 0x3f, sizeof f); for (int i = 0; i <= n; i ++ ) f[i][0] = 0; for (int i = 1; i <= n; i ++ ) for (int j = 1; j <= i; j ++ ) { if (a[i] == b[j]) { f[i][j] = f[i - 1][j - 1]; } else f[i][j] = min(f[i - 1][j], f[i - 1][j - 1] + 1); } cout << f[n][m] << endl; return 0; }

G 排列数

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream> using namespace std; #define mod 123456 #define N 505 int dp[N][N]; int main() { int n, k; cin >> n >> k; dp[1][0] = 1; for(int i = 2; i <= n; i++){//第i个数前面有j个折点 dp[i][0] = 2; for(int j = 0; j <= i-2; j++){ dp[i][j] %= mod; dp[i+1][j] += dp[i][j] * (j+1); dp[i+1][j+1] += dp[i][j] * 2; dp[i+1][j+2] += dp[i][j] * (i-j-2); } } cout << dp[n][k-1] % mod << endl; return 0; }

H 解谜游戏

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream> #include <cstring> #include <algorithm> #include <map> using namespace std; int main() { string a, b, c; int T; scanf("%d", &T); while (T -- ) { cin >> c >> b >> a; bool flag = true; for (int i = 0; i < 4; i ++ ) { map<char, int> mp; mp[a[i]] ++ ; mp[b[i]] ++ ; mp[b[i + 4]] ++ ; mp[c[i]] ++ ; mp[c[i + 4]] ++ ; mp[c[i + 8]] ++ ; if (mp['Y'] != 1 || mp['R'] != 2 || mp['G'] != 3) { flag = false; break; } } if (flag) puts("YES"); else puts("NO"); } return 0; }

I 第八大奇迹

线段树模板题,比较简单但是没有学过,学完后更

复制代码
1
2
在这里插入代码片

H 燃烧权杖

不会,抱歉

复制代码
1
2
在这里插入代码片

最后

以上就是魁梧电话最近收集整理的关于第十届蓝桥杯C++B组题解的全部内容,更多相关第十届蓝桥杯C++B组题解内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(84)

评论列表共有 0 条评论

立即
投稿
返回
顶部