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;
}

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. C++操作符重载(operator)

    c++操作符 例如-=+*/等,甚至包括,<<等都是操作符.c++特色之一就是给予完全重构和重载操作符(Java不可以,c#操作部分). 例子入手 假设一个结构体,定义如下 struct ...

  2. 使用AWS SageMaker进行机器学习项目

    使用AWS SageMaker进行机器学习项目 本文主要介绍如何使用AWS SageMaker进行机器学习项目. 1. 题目 使用的题目为阿里天池的"工业蒸汽量预测",题目地址为: ...

  3. Ubuntu 18.04 安装OneDrive自动同步

    Ubuntu 18.04 安装OneDrive自动同步 Windows10系统已经自带了OneDrive的自动同步功能,对于多设备用户而言已经成为了一个非常方便传输保存文件的途径,在Ubuntu下也有 ...

  4. UART和RS232、RS485的关系是什么?

    串口通讯是电子工程师和嵌入式开发工程师面对的最基本问题,RS232则是其中最简单最常用的通讯方式.但是初学者往往搞不清有关的名词如UART和RS232或RS485之间是什么关系,因为它们经常被放到语句 ...

  5. FLUTTER 中 Isolate 的一个例子.

    isolate 起因 最近看了一点isolate的东西, 自己写了一个例子. 普通的的 consummer-producer例子是只有前后两端的,实际上,会把前后两端再进行包装. 我这里这个例子,是把 ...

  6. ubuntu insight卸载

    最近需要进行gdb调试,但感觉gdb命令行方式不够直观,于是按照教程下载安装了insight,期间各种出错和bug,好不容易安装完成,却发现安装后的gdb版本变成了6.8-1,与gcc版本不兼容. 无 ...

  7. CosyVoice多语言、音色和情感控制模型,one-shot零样本语音克隆模型本地部署(Win/Mac),通义实验室开源

    近日,阿里通义实验室开源了CosyVoice语音模型,它支持自然语音生成,支持多语言.音色和情感控制,在多语言语音生成.零样本语音生成.跨语言声音合成和指令执行能力方面表现卓越. CosyVoice采 ...

  8. MySQL索引种类

    normal:表示普通索引 unique:表示唯一的,不允许重复的索引,如果该字段信息保证不会重复例如身份证号用作索引时,可设置为unique full textl: 表示 全文搜索的索引. FULL ...

  9. 阿里云服务器Docket安装RabbitMQ 3.8.12

    DocketMQ安装RabbitMQ 地址:https://hub.docker.com/ 拉取镜像 docker pull rabbitmq:3.8.12-management-alpine 运行 ...

  10. 24 年 “年薪百万” 的 Java 程序员,都要学什么?

    大家好,我是程序员鱼皮.前几天我看了一篇由国外的 Java 架构师大佬分享的文章,主题是 "Java 架构师必会的 20 个技术". 光看这个标题,就知道在国外做 Java 开发, ...