2023 睿抗机器人开发者大赛CAIP-编程技能赛-高职组(省赛)解题报告 | 珂学家
前言
题解
2023 睿抗机器人开发者大赛CAIP-编程技能赛-高职组(省赛)。
基础语法+STL入门题+基础数论。
RC-v1 好之者不如乐知者
分值: 5分
签到题,hello world的各种变体
#include <bits/stdc++.h>using namespace std;int main() {cout << "How Can We Live a Joyful Life\n";cout << "Without Programming\n";return 0;
}
RC-v2 陈依涵的高情商体重计算器
分值: 10分
语法题,夹带各种if else逻辑 + 输出格式化
#include <bits/stdc++.h>using namespace std;int main() {int n;cin >> n;if (n > 100) n = 100;else if (n % 10 != 0) n = n / 10 * 10;else n -= 10;cout << "Gong xi nin! Nin de ti zhong yue wei: " << n << " duo jin\n";return 0;
}
RC-v3 环岛自行车赛
分值: 10分
分段函数,求平均速度
#include <bits/stdc++.h>using namespace std;int main() {int n;cin >> n;int dist = 0, acc = 0;for (int i = 0; i < n; i++) {int d; cin >> d;dist += d;}for (int i = 0; i < n; i++) {int t; cin >> t;acc += t;}cout << fixed << setprecision(1) << (dist * 60.0 / acc) << endl; return 0;
}
RC-v4 两位数加法练习
分值:15分
题型: 模拟题
#include <bits/stdc++.h>using namespace std;int main() {string s;cin >> s;int n = s.size();for (int i = 0, j = n - 1; i < j; i+=2, j-=2) {int left = (s[i] - '0') * 10 + (s[j] - '0');int right = (s[i + 1] - '0') * 10 + (s[j - 1] - '0');cout << left << "+" << right << "=" << (left + right) << "\n";}return 0;
}
RC-v5 配花束
分值: 15分
思路: 求最小值
#include <bits/stdc++.h>using namespace std;int main() {int n;cin >> n;vector<int> vec(n);for (int &x: vec) cin >> x;cout << *min_element(vec.begin(), vec.end()) << endl;
}
RC-v6 数合数
分值: 20分
思路: 枚举 + 质数判定
#include <bits/stdc++.h>using namespace std;bool isPrime(int v) {if (v <= 1) return false;int j = 2;int fac = 0;while (j <= v / j) {if (v % j == 0) {while (v % j == 0) {v/=j;fac ++;}}j++;}if (v > 1) fac++;return fac == 1;
}int main() {int a, b, n;cin >> a >> b >> n;vector<int> vec(n);for (int &x: vec) cin >> x;int ans = 0;for (int i = a; i <= b; i++) {bool f = false;for (int v: vec) {if (i % v == 0) {f = true;break;}}if (f) continue;if (!isPrime(i)) ans++;}cout << ans << endl;return 0;
}
RC-v7 翻箱倒柜
分值: 25分
STL 容器题,这边考察二元组作为key的使用
#include <bits/stdc++.h>using namespace std;struct Box {int c, w, g;Box(int c, int w, int g) : c(c), w(w), g(g) {}bool operator<(const Box &lhs) const {if (c != lhs.c) return c < lhs.c;if (w != lhs.w) return w < lhs.w;return g < lhs.g;}
};int main() {int n;cin >> n;map<Box, string> hp;for (int i = 0; i < n; i++) {int c, w, g;cin >> c >> w >> g;string color;cin >> color;hp[Box(c, w, g)] = color;}int q;cin >> q;for (int i = 0; i < q; i++) {int c, w, g;cin >> c >> w >> g;Box box(c, w, g);if (hp.count(box) > 0) {cout << hp[box] << "\n";} else {cout << "Not Found\n";}}return 0;
}