2023第十四届蓝桥杯国赛 C/C++ 大学 B 组 (赛后记录)

您所在的位置:网站首页 蓝桥杯c语言b组试题 2023第十四届蓝桥杯国赛 C/C++ 大学 B 组 (赛后记录)

2023第十四届蓝桥杯国赛 C/C++ 大学 B 组 (赛后记录)

2023-06-11 18:18| 来源: 网络整理| 查看: 265

2023 第十四届蓝桥杯国赛 C / C + + 大学 B 组 2023第十四届蓝桥杯国赛 C/C++ 大学 B 组 2023第十四届蓝桥杯国赛C/C++大学B组

点我查看题目PDF 前言

由于是学校期末复习周, 很多算法没有复习, 结果考了一堆板题 (悲

赛后代码记录 A题 子 2023

直接跑暴力就行, 应该没啥问题

#include #define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define de(a) cout if (cnt == 4) { res++; return; } if (u >= sz(s)) return; if (s[u] == op[cnt]) dfs(u + 1, cnt + 1); dfs(u + 1, cnt); } string get(string s) { string res; for (auto &c: s) { if (c == '2' || c == '0' || c == '3') res += c; } return res; } void solve() { for (int i = 1; i for (int i = 2; i vis[i * primes[j]] = true; if (i % primes[j] == 0) break; } } } void solve() { get_p(); int res = 0; for (int i = 0; i IOS; int T = 1; // cin >> T; cin.get(); while (T --) solve(); return 0; } 错误答案 res = 947303 update 感谢群友让我知道我得分-5, 这里计算中long long爆掉了, 需要 __int128正确答案 res = 947293 C题 班级活动

more 表示所有id中人数多于两个的人数去掉匹配的 2 位剩下的总人数,one 表示只有一个的人数,如果 more 大于等于 one 输出 more,否则输出 more + (one-more)/ 2

#include #define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define de(a) cout cin >> x; cnt[x]++; } int one = 0, more = 0; for (auto [x, c]: cnt) { if (c == 1) one++; else if (c > 2) more += c - 2; } if (more >= one) cout cin >> n >> m; for (int i = 1; i > a[i]; for (int i = 1; i > b[i]; int res = 0; int suma = 0, sumb = 0; int i = 1, j = 1; while (i IOS; int T = 1; // cin >> T; cin.get(); while (T --) solve(); return 0; } E题 数三角

是个原… (我没做过 悲 附上原题连接 赛时直接 O ( n 3 ) O(n^3) O(n3)枚举了 (暴力 正解思路就是枚举所有顶点和该顶点能到的点的边长, 相同的顶点和边长可以组成等腰三角形, 但这样会出现三点共线的情况, 再把这一部分给减去就行

贴上正解代码 (感觉很对, 牛客的数据是过了 #include #define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define de(a) cout auto &[x, y] = p; cin >> x >> y; vis.insert(p); } auto get_dis = [] (PII &a, PII &b) { auto &[x1, y1] = a; auto &[x2, y2] = b; return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); }; vector edge; for (int i = 0; i return vis.count((PII){x, y}); }; // 三点共线数 cnt int cnt = 0; for (int i = 0; i return x >= 2? (x * (x - 1) / 2) : 0; }; int las_point = -1, las_dis = -1; int c = 0; int ans = 0; // 不考虑三点共线的情况的所有 共起点, 等边长 的三角形 for (auto &[po, dis]: edge) { if (po == las_point && dis == las_dis) { c++; } else { ans += calc(c); c = 1, las_point = po, las_dis = dis; } } cout -1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; int bfs(int sx, int sy) { memset(dist, 0x3f, sizeof dist); dist[sx][sy][1] = 0; queue q; // x y 以及到达该点的 c q.emplace(sx, sy, 1); while (q.size()) { auto [x, y, c] = q.front(); q.pop(); if (x == n && y == m) return dist[n][m][c]; bool turn = false; // 是否应该换字母走 if (c == k) turn = true; for (int i = 0; i if (dist[a][b][c + 1] > dist[x][y][c] + 1) { dist[a][b][c + 1] = dist[x][y][c] + 1; q.emplace(a, b, c + 1); } } if (turn && g[x][y] != g[a][b]) { if (dist[a][b][1] > dist[x][y][c] + 1) { dist[a][b][1] = dist[x][y][c] + 1; q.emplace(a, b, 1); } } } } return -1; // 没到达返回 -1 } void solve() { cin >> n >> m >> k; for (int i = 1; i > g[i] + 1; cout cin >> n >> m; for (int i = 1; i int L, R; cin >> L >> R; cout


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3