A 时间旅人的困境 - C++ 基本结构
while (c != 1) {
if (c & 1) c = c * 3 + 1;
else c >>= 1;
++ans;
} cout << ans << '\n';
B 完美风暴 - 数组
cin >> n;
for (int i = 1; i <= n; ++i) cin >> p[i];
for (int i = 1; i <= 7; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) ans += a[p[i]];
cout << ans << '\n';
C 加密的日记 - 字符与字符串
cin >> n;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
getline(cin, s);
for (auto &v : s) if (v != ' ') {
char base = isupper(v) ? 'A' : 'a';
v = (v - base + 26 - n) % 26 + base;
} cout << s << '\n';
D 图书馆管理系统 - 结构体与 STL
int n, x;
string op, name, author;
struct book {
string name, author;
bool borrowed;
};
map<int, book> mp;
cin >> n;
while (n--) {
x = 0;
cin >> op;
if (op == "ADD") {
cin >> name >> author >> x;
if (name.empty() || author.empty() || !x) {
cout << "Invalid\n";
break;
} mp[x].name = name, mp[x].author = author;
} else if (op == "QUERY") {
cin >> x;
if (!mp.count(x)) cout << "NotFound\n";
else {
if (mp[x].borrowed) cout << mp[x].name << ' ' << mp[x].author << ' ' << x << " Borrowed\n";
else cout << mp[x].name << ' ' << mp[x].author << ' ' << x << " Available\n";
}
} else if (op == "BORROW") {
cin >> x;
if (!mp.count(x)) cout << "NotFound\n";
else mp[x].borrowed = true;
} else {
cin >> x;
if (!mp.count(x)) cout << "NotFound\n";
else mp[x].borrowed = false;
}
}
E 方案 - 图的存储与遍历
const int N = 1010;
int t, n, m, r, u, v;
vector<pair<int, long long> > g[N];
long long k, w, dis[N], ans[N], sum;
void dfs(int u, int fa){
for (auto to : g[u]) {
int v = to.first;
long long w = to.second;
if(v == fa) continue;
dis[v] = dis[u] + w;
dfs(v, u);
}
}
cin >> t >> k;
for (int i = 1; i <= t; ++i){
for (int j = 1; j <= n; ++j) g[j].clear();
fill(dis + 1, dis + n + 1, 0);
cin >> n >> m >> r;
for (int i = 1; i <= m; ++i) {
cin >> u >> v >> w;
g[u].emplace_back(make_pair(v, w));
g[v].emplace_back(make_pair(u, w));
} dfs(r, 0);
for (int j = 1; j <= n; ++j) ans[i] = max(ans[i], dis[j]);
} for (int i = 1; i <= t; ++i) sum += ans[i];
if (sum >= k) cout << "YES\n" << sum << '\n';
else {
cout << "NO\n";
for (int i = 1; i <= t; ++i) cout << ans[i] << ' ';
}
F 血夜筝鸣 - 动态规划基础
cin >> n;
for (int i = 1; i <= n; ++i)
for (int j = 0; j < 3; ++j) cin >> a[i][j];
for (int i = 1; i <= n; ++i) {
f[i][0] = max(f[i - 1][0], max(f[i - 1][1], f[i - 1][2])) + a[i][0];
f[i][1] = max(f[i - 1][0], max(f[i - 1][1], f[i - 1][2])) + a[i][1];
f[i][2] = max(f[i - 1][0], f[i - 1][1]) + a[i][2];
} cout << max(f[n][0], max(f[n][1], f[n][2])) << '\n';