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. vue目录文件结构

    my-vue-app/ ├── node_modules/ # 依赖的第三方模块 ├── public/ # 公共文件,不会被打包 │ ├── index.html # 应用的入口 HTML 文件 │ ...

  2. Nuxt 3 路由系统详解:配置与实践指南

    title: Nuxt 3 路由系统详解:配置与实践指南 date: 2024/6/21 updated: 2024/6/21 author: cmdragon excerpt: 摘要:本文是一份关于 ...

  3. IoTBrowser V2.0:引领物联网时代的全新浏览器

    强大的兼容性,无限的可能 IoTBrowser V2.0,基于Chromium内核,完美支持H5/css/js开发界面,让您的物联网应用拥有与主流浏览器同等的流畅体验.同时,它还支持CSS 3动画.C ...

  4. 复习 - js基础语法

    今天继续复习了js基础语法  最后一天了 学完了进入dom bom的复习 今天发现了很多经典案例 我都不知道一个随笔放的完不 逻辑性感觉还是蛮强的 主要就是作用域 对象 内置对象等一些的操作嘛 话不多 ...

  5. Java中代码Bug记录--泛型失效、数组删除、HashMap死循环

    最近在工作的过程中,遇到了不少奇怪自己或者同事的Bug,都是一些出乎意料的,不太容易发现的,记录一下来帮助可能也遇到了这些Bug的人 1. 编译时泛型校验失效 Map<String, Strin ...

  6. 深度学习pytorch常用操作以及流程

    在微信公众号上看到这篇文章,担心以后想找的时候迷路,所以记录到了自己的博客上,侵扰致歉,随时联系可删除. 1.基本张量操作 1. 1 创建张量 介绍: torch.tensor() 是 PyTorch ...

  7. Spring Cloud微服务下如何配置I8n

    什么是I8n 国际化(I18n)指的是设计和开发产品的过程,使得它们能够适应多种语言和文化环境,而不需要进行大量的代码更改.这通常涉及到创建一个基础版本的产品,然后通过配置和资源文件来添加对不同语言和 ...

  8. 如何在 XAMPP 中使用 不同的 PHP 版本?

    你有没有碰到这种情况,你工作的项目需要的是PHP8,而你自己的项目需要的是PHP7,而你又特别钟爱于XAMPP,奈何它却不能自由切换PHP版本,下面就讲下本人在用的方法将PHP7更新到PHP8,可以通 ...

  9. suffix-icon属性隐藏el-select下拉框右边的下拉图标

    <el-form-item label="入库类型" prop="mt_type"> <el-select v-model="for ...

  10. vue小知识~eventBus

    eventBus是指在向全区暴露这个vue对象,此时在任意一个地方都可以使用vue相关的实例 在main.js配置 Vue.prototype.$bus=new Vue() 此时整个应用都可以使用vu ...