SMU 2024 spring 天梯赛1

7-1 种钻石 - SMU 2024 spring 天梯赛1 (pintia.cn)

  1. #include <bits/stdc++.h>
  2. #define debug(a) cout<<#a<<"="<<a<<'\n';
  3. using namespace std;
  4. using i64 = long long;
  5. typedef pair<i64, i64> PII;
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. int n, v;
  10. cin >> n >> v;
  11. cout << n / v << '\n';
  12. return 0;
  13. }

7-2 1-1 输出金字塔图案 - SMU 2024 spring 天梯赛1 (pintia.cn)

  1. *
  2. ***
  3. *****
  4. *******
  5. //PHP

7-3 强迫症 - SMU 2024 spring 天梯赛1 (pintia.cn)

  1. #include <bits/stdc++.h>
  2. #define debug(a) cout<<#a<<"="<<a<<'\n';
  3. using namespace std;
  4. using i64 = long long;
  5. typedef pair<i64, i64> PII;
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. string n;
  10. cin >> n;
  11. if (n.size() < 6) {
  12. if (n.substr(0, 2) < "22") {
  13. n = "20" + n;
  14. } else
  15. n = "19" + n;
  16. }
  17. cout << n.substr(0, 4) << '-' << n.substr(4) << '\n';
  18. return 0;
  19. }

7-4 小孩子才做选择,大人全都要 - SMU 2024 spring 天梯赛1 (pintia.cn)

注意点,一个空碗一个不为空时,这时都处于亏的状态,但是全都要不一定就代表一点也吃不到

  1. #include <bits/stdc++.h>
  2. #define debug(a) cout<<#a<<"="<<a<<'\n';
  3. using namespace std;
  4. using i64 = long long;
  5. typedef pair<i64, i64> PII;
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. int x,y;
  10. cin >> x >> y;
  11. if(x > 0 && y > 0){
  12. cout << max(x,y) << ' ' << x + y << "\n^_^";
  13. }else if(x < 0 && y < 0) {
  14. cout << "0 0\n-_-";
  15. }else{
  16. cout << max(x,y) << ' ' << max(0,x+y) << "\nT_T";
  17. }
  18. return 0;
  19. }

7-5 胎压监测 - SMU 2024 spring 天梯赛1 (pintia.cn)

模拟

  1. #include <bits/stdc++.h>
  2. #define debug(a) cout<<#a<<"="<<a<<'\n';
  3. using namespace std;
  4. using i64 = long long;
  5. typedef pair<i64, i64> PII;
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. vector<int> lun(6);
  10. for (auto &i : lun) cin >> i;
  11. int ma = lun[0];
  12. for (int i = 0; i < 4; i ++)
  13. ma = max(ma, lun[i]);
  14. int ck = -1,num = 0;
  15. for(int i = 0;i < 4;i ++){
  16. int x = abs(lun[i] - ma);
  17. if(x > lun[5] || lun[i] < lun[4]){
  18. num ++, ck = i;
  19. }
  20. }
  21. if(!num){
  22. cout << "Normal";
  23. }else if(num == 1){
  24. cout << "Warning: please check #" << ck + 1 << '!';
  25. }else{
  26. cout << "Warning: please check all the tires!";
  27. }
  28. return 0;
  29. }

7-6 吉老师的回归 - SMU 2024 spring 天梯赛1 (pintia.cn)

考察字符串

  1. #include <bits/stdc++.h>
  2. #define debug(a) cout<<#a<<"="<<a<<'\n';
  3. using namespace std;
  4. using i64 = long long;
  5. typedef pair<i64, i64> PII;
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. int n, m;
  10. cin >> n >> m;
  11. string s;
  12. getline(cin, s);
  13. for (int i = 0; i < n; i ++) {
  14. getline(cin, s);
  15. if(s.find("qiandao") == -1 && s.find("easy") == -1){
  16. m --;
  17. if(m == -1){
  18. cout << s << '\n';
  19. exit(0);
  20. }
  21. }
  22. }
  23. cout << "Wo AK le";
  24. return 0;
  25. }

7-7 静静的推荐 - SMU 2024 spring 天梯赛1 (pintia.cn)

两个成绩都满足要求的,直接答案加一即可,就不参与推荐名额,把满足天梯赛成绩的筛选出来后,取每个分数段的前k个即可

  1. #include <bits/stdc++.h>
  2. #define debug(a) cout<<#a<<"="<<a<<'\n';
  3. using namespace std;
  4. using i64 = long long;
  5. typedef pair<i64, i64> PII;
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. int n,k,s;
  10. cin >> n >> k >> s;
  11. int ans = 0;
  12. vector<int> m(300);
  13. for(int i = 0;i < n;i ++){
  14. int a,b;
  15. cin >> a >> b;
  16. if(a < 175) continue;
  17. if(b >= s) {
  18. ans ++;
  19. continue;
  20. }
  21. m[a] ++;
  22. }
  23. for(int i = 175;i <= 290;i ++)
  24. ans += (m[i] > k ? k : m[i]);
  25. cout << ans << '\n';
  26. return 0;
  27. }

7-8 机工士姆斯塔迪奥 - SMU 2024 spring 天梯赛1 (pintia.cn)

把选中的行和列都移到边界,最终答案仍然是个矩形,注意重复选择的行和列

  1. #include <bits/stdc++.h>
  2. #define debug(a) cout<<#a<<"="<<a<<'\n';
  3. using namespace std;
  4. using i64 = long long;
  5. typedef pair<i64, i64> PII;
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. i64 n,m,q;
  10. cin >> n >> m >> q;
  11. vector<array<int,2>> vis(100100);
  12. for(int i = 0;i < q;i ++){
  13. int op,x;
  14. cin >> op >> x;
  15. if(vis[x][op]) continue;
  16. vis[x][op] ++;
  17. if(op) m--;
  18. else n --;
  19. }
  20. cout << n * m << '\n';
  21. return 0;
  22. }

7-9 彩虹瓶 - SMU 2024 spring 天梯赛1 (pintia.cn)

模拟

  1. #include <bits/stdc++.h>
  2. #define debug(a) cout<<#a<<"="<<a<<'\n';
  3. using namespace std;
  4. using i64 = long long;
  5. typedef pair<i64, i64> PII;
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. int n,m,k;
  10. cin >> n >> m >> k;
  11. while(k--){
  12. stack<int> Q,now;
  13. for(int i = 0;i < n;i ++){
  14. int x;
  15. cin >> x;
  16. if(Q.size() > m) continue;
  17. if(now.empty() && x == 1){
  18. now.push(x);
  19. }else if(now.size() && x == now.top() + 1){
  20. now.push(x);
  21. }else Q.push(x);
  22. if(now.size()){
  23. while(Q.size() && Q.top() == now.top() + 1){
  24. now.push(Q.top());
  25. Q.pop();
  26. }
  27. }
  28. }
  29. if(now.size() != n)
  30. cout << "NO\n";
  31. else cout << "YES\n";
  32. }
  33. return 0;
  34. }

7-10 简单计算器 - SMU 2024 spring 天梯赛1 (pintia.cn)

模拟

  1. #include <bits/stdc++.h>
  2. #define debug(a) cout<<#a<<"="<<a<<'\n';
  3. using namespace std;
  4. using i64 = long long;
  5. typedef pair<i64, i64> PII;
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. int n;
  10. cin >> n;
  11. vector<int> num(n);
  12. for (auto &i : num) cin >> i;
  13. vector<char> op(n - 1);
  14. for (auto &i : op) cin >> i;
  15. while (num.size() > 1) {
  16. int x = num.back();
  17. num.pop_back();
  18. int y = num.back();
  19. num.pop_back();
  20. char z = op.back();
  21. op.pop_back();
  22. switch (z) {
  23. case '+': num.push_back(x + y);
  24. break;
  25. case '-': num.push_back(y - x);
  26. break;
  27. case '*': num.push_back(x * y);
  28. break;
  29. case'/': if (!x) {
  30. cout << "ERROR: " << y << "/0\n";
  31. exit(0);
  32. } else {
  33. num.push_back(y / x);
  34. break;
  35. }
  36. }
  37. }
  38. cout << num[0] << '\n';
  39. return 0;
  40. }

7-11 龙龙送外卖 - SMU 2024 spring 天梯赛1 (pintia.cn)

假设每次送完后都要回到外卖站,则通过画图可以发现,其实每条路都走了两遍,现在加上不必返回外卖站,那我们只要把离外卖站即根节点最远的那条路线放到最后走,即只需走一遍,在之前的每条路的基础上减去最远的那条线即可

刚开始用了LCA,不过跟这题没关系,只需要计算每个点的深度以及记录其父节点,然后往上递归即可;

  1. #include <bits/stdc++.h>
  2. #define debug(a) cout<<#a<<"="<<a<<'\n';
  3. using namespace std;
  4. using i64 = long long;
  5. typedef pair<i64, i64> PII;
  6. struct LCA {
  7. int n;
  8. vector<i64> dep;
  9. vector<vector<int>> e;
  10. vector<array<int, 21>> fa;
  11. LCA() {}
  12. LCA(int n) {
  13. dep.resize(n + 1);
  14. e.resize(n + 1);
  15. fa.resize(n + 1);
  16. }
  17. void add(int u, int v) {
  18. e[u].push_back(v);
  19. e[v].push_back(u);
  20. }
  21. //计算深度,处理各点祖先
  22. void dfs(int u, int father) {
  23. dep[u] = dep[father] + 1;
  24. fa[u][0] = father;
  25. for (int i = 1; i < 20; i ++)
  26. fa[u][i] = fa[fa[u][i - 1]][i - 1];
  27. for (auto v : e[u])
  28. if (v != father)
  29. dfs(v, u);
  30. }
  31. //最近公共祖先
  32. //两点集并的最近公共祖先为两点几分别的最近公共祖先的最近公共祖先,
  33. //即LCA(A∪B) = LCA(LCA(A), LCA(B));
  34. int lca(int u, int v) {
  35. if (dep[u] < dep[v]) swap(u, v);
  36. for (int i = 19; i >= 0; i --)
  37. if (dep[fa[u][i]] >= dep[v])
  38. u = fa[u][i];
  39. if (u == v) return v;
  40. for (int i = 19; i >= 0; i --)
  41. if (fa[u][i] != fa[v][i])
  42. u = fa[u][i], v = fa[v][i];
  43. return fa[u][0];
  44. }
  45. //d(u,v) = h(u) + h(v) - 2h(LCA(u,v));
  46. //其中d是树上两点间的距离,h代表某点到树根的距离
  47. int get_dis(int u, int v) {
  48. return dep[u] + dep[v] - 2 * dep[lca(u, v)];
  49. }
  50. };
  51. int main() {
  52. ios::sync_with_stdio(false);
  53. cin.tie(nullptr);
  54. int n, m, root;
  55. cin >> n >> m;
  56. LCA lca(n);
  57. for (int i = 1; i <= n; i ++) {
  58. int x;
  59. cin >> x;
  60. if (x == -1) root = i, x ++;
  61. lca.add(x, i);
  62. }
  63. lca.dfs(root, 0);
  64. i64 ans = 0;
  65. vector<bool> vis(n + 1);
  66. vis[root] = 1;
  67. auto dfs = [&](auto self, int u)->void{
  68. if (vis[u]) return ;
  69. vis[u] = 1;
  70. ans += 2;
  71. self(self, lca.fa[u][0]);
  72. };
  73. i64 ma = 0;
  74. while (m --) {
  75. int x;
  76. cin >> x;
  77. ma = max(ma, lca.dep[x]);
  78. dfs(dfs, x);
  79. cout << ans - ma + 1 << '\n';
  80. }
  81. return 0;
  82. }

7-12 智能护理中心统计 - SMU 2024 spring 天梯赛1(补题) (pintia.cn)

维护每个管理节点的人数,管理中心与管理中心的从属关系,老人与管理中心的从属关系;

每加入/移除一个老人,从当前老人的管理中心往上递归加一/减一;

管理中心之间从属关系,就往上递归给其上级添加此中心的人数;

查询时,先将老人从原来的管理中心移除,再添加到新的管理中心;

  1. #include <bits/stdc++.h>
  2. #define debug(a) cout<<#a<<"="<<a<<'\n';
  3. using namespace std;
  4. using i64 = long long;
  5. typedef pair<i64, i64> PII;
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. int n, m;
  10. cin >> n >> m;
  11. map<int, int> num, fa, people;
  12. map<string, int> id;
  13. auto up = [&](auto up, int x)->void{
  14. if (!x) return;
  15. num[x] ++;
  16. up(up, fa[x]);
  17. };
  18. auto down = [&](auto down, int x)->void{
  19. if (!x) return ;
  20. num[x] --;
  21. down(down, fa[x]);
  22. };
  23. auto pass = [&](auto pass, int x, int val)->void{
  24. if (!x) return ;
  25. num[x] += val;
  26. pass(pass, fa[x], val);
  27. };
  28. int cnt = 0;
  29. for (int i = 0; i < m; i ++) {
  30. string x, y;
  31. cin >> x >> y;
  32. if (!id[y]) id[y] = ++ cnt;
  33. if (x[0] >= '0' && x[0] <= '9') {
  34. people[stoi(x)] = id[y];
  35. up(up, id[y]);
  36. } else {
  37. if (!id[x]) id[x] = ++ cnt;
  38. fa[id[x]] = id[y];
  39. pass(pass, id[y], num[id[x]]);
  40. }
  41. }
  42. char op;
  43. while (cin >> op) {
  44. int x;
  45. string y;
  46. if (op == 'E') break;
  47. else if (op == 'T') {
  48. cin >> x >> y;
  49. down(down, people[x]);
  50. people[x] = id[y];
  51. up(up, id[y]);
  52. } else {
  53. cin >> y;
  54. cout << num[id[y]] << '\n';
  55. }
  56. }
  57. return 0;
  58. }

SMU 2024 spring 天梯赛1的更多相关文章

  1. 【CCCC天梯赛决赛】

    cccc的天梯赛决赛,水题一样的水,中档题以上的还是没做出来.补了一下题,觉得其实也不是很难,主要是练的少. L2-1:红色预警 并查集 我做的时候想不到并查集,想到了也不一定做的出来,都是其实不难. ...

  2. 记第一届 CCCC-团体程序设计天梯赛决赛 参赛

    其他都没什么,上午报道,下午比赛两个半小时,最后139分 但四我超遗憾的是,最后在做L3-1二叉搜索树,因为看到有辣么多人做出来,可是我没做出来啊 比赛结束后看了看其他两道当场吐血,L3-3直捣黄龙不 ...

  3. L1-049 天梯赛座位分配​​​​​​​

    L1-049 天梯赛座位分配 (20 分) 天梯赛每年有大量参赛队员,要保证同一所学校的所有队员都不能相邻,分配座位就成为一件比较麻烦的事情.为此我们制定如下策略:假设某赛场有 N 所学校参赛,第 i ...

  4. 团体程序设计天梯赛(CCCC) L3021 神坛 的一些错误做法(目前网上的方法没一个是对的) 和 一些想法

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  5. 团体程序设计天梯赛(CCCC) L3019 代码排版 方法与编译原理密切相关,只有一个测试点段错误

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  6. 团体程序设计天梯赛(CCCC) L3015 球队“食物链” 状态压缩

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code #include <cstdio> #include ...

  7. 第四届CCCC团体程序设计天梯赛 后记

    一不小心又翻车了,第二次痛失200分 1.开局7分钟A了L2-3,一看榜已经有七个大兄弟排在前面了,翻车 * 1 2.把L1-3 A了18分,留了两分准备抢顽强拼搏奖,最后五秒钟把题过了,万万没想到还 ...

  8. 团体程序设计天梯赛(CCCC) L3014 周游世界 BFS证明

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  9. 团体程序设计天梯赛(CCCC) L3013 非常弹的球 不同思路

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  10. 团体程序设计天梯赛(CCCC) L3012 水果忍者 上凸或下凹的证明

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code #include <cstdio> #include ...

随机推荐

  1. 关于vue中image控件,onload事件里,event.target 为null的奇怪问题探讨

    废话不多说(主要文笔比较差),直接上代码 一个简单的demo,如下 <img :src="orginalImgSrc" style="display: none;& ...

  2. 【BUG记录】Cause: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x90\xA6' for column 'name' at row 1

    大家好呀,我是summo,这次的文章标题是一个Mysql数据库的SQL错误,遇到的同学自然懂,没遇到的同学希望你永远也不要遇到. 一.错误说明 Cause: java.sql.SQLException ...

  3. Java的运行机制和JDK,JRE,JVM的区别

    源文件(Java文件)   >  编译器  > 字节码(class文件)  >  JVM(java虚拟机)  >  操作系统  1.java首先利用文本编辑器写java源程序, ...

  4. “科来杯”第九届山东省大学生网络安全技能大赛决赛部分wp

      1.损坏的流量包 wireshark打不开,丢进winhex里,找关键字flag 哎,没找到. 那就仔细看看,在最后发现一串类似base64的密文 base64解密 得到flag 2.签到题 一个 ...

  5. 《DNK210使用指南 -CanMV版 V1.0》第二章 Kendryte K210简介

    第二章 Kendryte K210简介 1)实验平台:正点原子DNK210开发板 2)章节摘自[正点原子]DNK210使用指南 - CanMV版 V1.0 3)购买链接:https://detail. ...

  6. Ubuntu20.04之Nvidia驱动安装

    参考:https://blog.csdn.net/xiaokedou_hust/article/details/82187860,实际操作时和该博文有些出入,故作优化. s1.连接wifi,打开终端. ...

  7. java --面试题大全

            J2EE面试题   文档版本号:V2.0                   2016年11月 目 录 1. Java基础部分 8 1.1. 一个".java"源文 ...

  8. 一款EF Core下高性能、轻量级针对分表分库读写分离的解决方案

    前言 今天大姚给大家分享一款EF Core下高性能.轻量级针对分表分库读写分离的解决方案,开源(Apache License)的EF Core拓展程序包:ShardingCore. ShardingC ...

  9. Redis缓存雪崩,击穿,穿透以及解决方案

    Redis读写过程 一般情况下,Redis都是作为client与MySQL间的一层缓存,尽量减少MySQL的读压力,数据流向如图所示: Redis的五种数据类型及使用场景 String 这个其实没啥好 ...

  10. Oracle 启用、禁用触发器

    基本语法 启用指定表中所有触发器(trigger) alter table table_name enable all triggers; 语法: alter table 表名 enable all ...