SMU 2024 spring 天梯赛1
SMU 2024 spring 天梯赛1
7-1 种钻石 - SMU 2024 spring 天梯赛1 (pintia.cn)
#include <bits/stdc++.h> #define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std; using i64 = long long; typedef pair<i64, i64> PII; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, v; cin >> n >> v; cout << n / v << '\n'; return 0; }
7-2 1-1 输出金字塔图案 - SMU 2024 spring 天梯赛1 (pintia.cn)
* *** ***** ******* //PHP
7-3 强迫症 - SMU 2024 spring 天梯赛1 (pintia.cn)
#include <bits/stdc++.h> #define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std; using i64 = long long; typedef pair<i64, i64> PII; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string n; cin >> n; if (n.size() < 6) { if (n.substr(0, 2) < "22") { n = "20" + n; } else n = "19" + n; } cout << n.substr(0, 4) << '-' << n.substr(4) << '\n'; return 0; }
7-4 小孩子才做选择,大人全都要 - SMU 2024 spring 天梯赛1 (pintia.cn)
注意点,一个空碗一个不为空时,这时都处于亏的状态,但是全都要不一定就代表一点也吃不到
#include <bits/stdc++.h> #define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std; using i64 = long long; typedef pair<i64, i64> PII; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int x,y; cin >> x >> y; if(x > 0 && y > 0){ cout << max(x,y) << ' ' << x + y << "\n^_^"; }else if(x < 0 && y < 0) { cout << "0 0\n-_-"; }else{ cout << max(x,y) << ' ' << max(0,x+y) << "\nT_T"; } return 0; }
7-5 胎压监测 - SMU 2024 spring 天梯赛1 (pintia.cn)
模拟
#include <bits/stdc++.h> #define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std; using i64 = long long; typedef pair<i64, i64> PII; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); vector<int> lun(6); for (auto &i : lun) cin >> i; int ma = lun[0]; for (int i = 0; i < 4; i ++) ma = max(ma, lun[i]); int ck = -1,num = 0; for(int i = 0;i < 4;i ++){ int x = abs(lun[i] - ma); if(x > lun[5] || lun[i] < lun[4]){ num ++, ck = i; } } if(!num){ cout << "Normal"; }else if(num == 1){ cout << "Warning: please check #" << ck + 1 << '!'; }else{ cout << "Warning: please check all the tires!"; } return 0; }
7-6 吉老师的回归 - SMU 2024 spring 天梯赛1 (pintia.cn)
考察字符串
#include <bits/stdc++.h> #define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std; using i64 = long long; typedef pair<i64, i64> PII; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; string s; getline(cin, s); for (int i = 0; i < n; i ++) { getline(cin, s); if(s.find("qiandao") == -1 && s.find("easy") == -1){ m --; if(m == -1){ cout << s << '\n'; exit(0); } } } cout << "Wo AK le"; return 0; }
7-7 静静的推荐 - SMU 2024 spring 天梯赛1 (pintia.cn)
两个成绩都满足要求的,直接答案加一即可,就不参与推荐名额,把满足天梯赛成绩的筛选出来后,取每个分数段的前k个即可
#include <bits/stdc++.h> #define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std; using i64 = long long; typedef pair<i64, i64> PII; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n,k,s; cin >> n >> k >> s; int ans = 0; vector<int> m(300); for(int i = 0;i < n;i ++){ int a,b; cin >> a >> b; if(a < 175) continue; if(b >= s) { ans ++; continue; } m[a] ++; } for(int i = 175;i <= 290;i ++) ans += (m[i] > k ? k : m[i]); cout << ans << '\n'; return 0; }
7-8 机工士姆斯塔迪奥 - SMU 2024 spring 天梯赛1 (pintia.cn)
把选中的行和列都移到边界,最终答案仍然是个矩形,注意重复选择的行和列
#include <bits/stdc++.h> #define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std; using i64 = long long; typedef pair<i64, i64> PII; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); i64 n,m,q; cin >> n >> m >> q; vector<array<int,2>> vis(100100); for(int i = 0;i < q;i ++){ int op,x; cin >> op >> x; if(vis[x][op]) continue; vis[x][op] ++; if(op) m--; else n --; } cout << n * m << '\n'; return 0; }
7-9 彩虹瓶 - SMU 2024 spring 天梯赛1 (pintia.cn)
模拟
#include <bits/stdc++.h> #define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std; using i64 = long long; typedef pair<i64, i64> PII; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n,m,k; cin >> n >> m >> k; while(k--){ stack<int> Q,now; for(int i = 0;i < n;i ++){ int x; cin >> x; if(Q.size() > m) continue; if(now.empty() && x == 1){ now.push(x); }else if(now.size() && x == now.top() + 1){ now.push(x); }else Q.push(x); if(now.size()){ while(Q.size() && Q.top() == now.top() + 1){ now.push(Q.top()); Q.pop(); } } } if(now.size() != n) cout << "NO\n"; else cout << "YES\n"; } return 0; }
7-10 简单计算器 - SMU 2024 spring 天梯赛1 (pintia.cn)
模拟
#include <bits/stdc++.h> #define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std; using i64 = long long; typedef pair<i64, i64> PII; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> num(n); for (auto &i : num) cin >> i; vector<char> op(n - 1); for (auto &i : op) cin >> i; while (num.size() > 1) { int x = num.back(); num.pop_back(); int y = num.back(); num.pop_back(); char z = op.back(); op.pop_back(); switch (z) { case '+': num.push_back(x + y); break; case '-': num.push_back(y - x); break; case '*': num.push_back(x * y); break; case'/': if (!x) { cout << "ERROR: " << y << "/0\n"; exit(0); } else { num.push_back(y / x); break; } } } cout << num[0] << '\n'; return 0; }
7-11 龙龙送外卖 - SMU 2024 spring 天梯赛1 (pintia.cn)
假设每次送完后都要回到外卖站,则通过画图可以发现,其实每条路都走了两遍,现在加上不必返回外卖站,那我们只要把离外卖站即根节点最远的那条路线放到最后走,即只需走一遍,在之前的每条路的基础上减去最远的那条线即可
刚开始用了LCA,不过跟这题没关系,只需要计算每个点的深度以及记录其父节点,然后往上递归即可;
#include <bits/stdc++.h> #define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std; using i64 = long long; typedef pair<i64, i64> PII; struct LCA { int n; vector<i64> dep; vector<vector<int>> e; vector<array<int, 21>> fa; LCA() {} LCA(int n) { dep.resize(n + 1); e.resize(n + 1); fa.resize(n + 1); } void add(int u, int v) { e[u].push_back(v); e[v].push_back(u); } //计算深度,处理各点祖先 void dfs(int u, int father) { dep[u] = dep[father] + 1; fa[u][0] = father; for (int i = 1; i < 20; i ++) fa[u][i] = fa[fa[u][i - 1]][i - 1]; for (auto v : e[u]) if (v != father) dfs(v, u); } //最近公共祖先 //两点集并的最近公共祖先为两点几分别的最近公共祖先的最近公共祖先, //即LCA(A∪B) = LCA(LCA(A), LCA(B)); int lca(int u, int v) { if (dep[u] < dep[v]) swap(u, v); for (int i = 19; i >= 0; i --) if (dep[fa[u][i]] >= dep[v]) u = fa[u][i]; if (u == v) return v; for (int i = 19; i >= 0; i --) if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i]; return fa[u][0]; } //d(u,v) = h(u) + h(v) - 2h(LCA(u,v)); //其中d是树上两点间的距离,h代表某点到树根的距离 int get_dis(int u, int v) { return dep[u] + dep[v] - 2 * dep[lca(u, v)]; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, root; cin >> n >> m; LCA lca(n); for (int i = 1; i <= n; i ++) { int x; cin >> x; if (x == -1) root = i, x ++; lca.add(x, i); } lca.dfs(root, 0); i64 ans = 0; vector<bool> vis(n + 1); vis[root] = 1; auto dfs = [&](auto self, int u)->void{ if (vis[u]) return ; vis[u] = 1; ans += 2; self(self, lca.fa[u][0]); }; i64 ma = 0; while (m --) { int x; cin >> x; ma = max(ma, lca.dep[x]); dfs(dfs, x); cout << ans - ma + 1 << '\n'; } return 0; }
7-12 智能护理中心统计 - SMU 2024 spring 天梯赛1(补题) (pintia.cn)
维护每个管理节点的人数,管理中心与管理中心的从属关系,老人与管理中心的从属关系;
每加入/移除一个老人,从当前老人的管理中心往上递归加一/减一;
管理中心之间从属关系,就往上递归给其上级添加此中心的人数;
查询时,先将老人从原来的管理中心移除,再添加到新的管理中心;
#include <bits/stdc++.h> #define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std; using i64 = long long; typedef pair<i64, i64> PII; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; map<int, int> num, fa, people; map<string, int> id; auto up = [&](auto up, int x)->void{ if (!x) return; num[x] ++; up(up, fa[x]); }; auto down = [&](auto down, int x)->void{ if (!x) return ; num[x] --; down(down, fa[x]); }; auto pass = [&](auto pass, int x, int val)->void{ if (!x) return ; num[x] += val; pass(pass, fa[x], val); }; int cnt = 0; for (int i = 0; i < m; i ++) { string x, y; cin >> x >> y; if (!id[y]) id[y] = ++ cnt; if (x[0] >= '0' && x[0] <= '9') { people[stoi(x)] = id[y]; up(up, id[y]); } else { if (!id[x]) id[x] = ++ cnt; fa[id[x]] = id[y]; pass(pass, id[y], num[id[x]]); } } char op; while (cin >> op) { int x; string y; if (op == 'E') break; else if (op == 'T') { cin >> x >> y; down(down, people[x]); people[x] = id[y]; up(up, id[y]); } else { cin >> y; cout << num[id[y]] << '\n'; } } return 0; }
本文作者:Ke_scholar
本文链接:https://www.cnblogs.com/Kescholar/p/18078408
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步