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); string s;
cin >> s;
cout << "Hello " << s << '\n'; return 0;
}

7-2 日期格式化 - 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 m,d,y;
scanf("%d-%d-%d",&m,&d,&y);
printf("%d-%02d-%02d\n",y,m,d); return 0;
}

7-3 寻找250 - 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,i = 0;
while(1){
i ++;
cin >> x;
if(x == 250){
cout << i << '\n';
exit(0);
}
} 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 n;
cin >> n;
for(int i = 0;i < n;i ++){
string s;
int x,y;
cin >> s >> x >> y;
if(x < 15 || x > 20 || y < 50 || y > 70){
cout << s << '\n';
}
} return 0;
}

7-5 矩阵A乘以B - 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 ra,ca,rb,cb; cin >> ra >> ca;
vector A(ra,vector<int>(ca));
for(int i = 0;i < ra;i ++)
for(int j = 0;j < ca;j ++)
cin >> A[i][j];
cin >> rb >> cb;
vector B(rb,vector<int>(cb));
for(int i =0;i < rb;i ++)
for(int j =0;j < cb;j ++)
cin >> B[i][j]; if(ca != rb){
cout << "Error: " << ca << " != " << rb << '\n';
}else{
cout << ra << ' ' << cb << '\n';
for(int i = 0;i < ra;i ++){
for(int j = 0;j < cb;j ++){
int res = 0;
for(int k = 0;k < ca;k ++)
res += A[i][k] * B[k][j];
cout << res << " \n"[j == cb - 1];
}
}
}
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 k, i = 0;
cin >> k;
string s;
cin >> s;
while(s != "End"){
i ++;
if(i % (k + 1) == 0){
cout << s << '\n';
}else{
if(s == "ChuiZi") cout << "Bu\n";
else if(s == "JianDao") cout << "ChuiZi\n";
else cout << "JianDao\n";
}
cin >> s;
} return 0;
}

7-7 整除光棍 - SMU 2024 spring 天梯赛自主训练1 (pintia.cn)

C++暴力过不了,Python可以;

维护一个全为1的字段以及其位数,每次记得取模;

#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;
cin >> x;
int num = 1,cnt = 1;
while(num < x){
num *= 10, num ++;
cnt ++;
} while(1){
cout << num / x;
num %= x;
if(!num){
break;
}
num *= 10;
num ++;
cnt ++;
}
cout << ' ' << cnt << '\n'; return 0;
}

7-8 阅览室 - SMU 2024 spring 天梯赛自主训练1 (pintia.cn)

测试点1,一本书多次借走,以最后一次时间为准,一本书多次返还,以第一次时间为准;

测试点3,平均阅读时间四舍五入;

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; typedef pair<i64, i64> PII; struct Book{
bool f = false;
int st,ed;
}; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int n;
cin >> n;
for(int i = 0;i < n;i ++){
vector<Book> Bu(1010);
int shu,h,m,sum = 0,num = 0,now = 0;
char key,op;
cin >> shu >> key >> h >> op >> m;
while(shu){
now = h * 60 + m;
if(key == 'E' && Bu[shu].f){
num ++,sum += now - Bu[shu].st;
Bu[shu].f = false;
}else if(key == 'S'){
Bu[shu].f = true;
Bu[shu].st = max(now,Bu[shu].st);
}
cin >> shu >> key >> h >> op >> m;
}
cout << num << ' ' << (num ? round(sum*1.0/num) : 0) << '\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;
cin >> n;
map<string,set<int>> Name;
vector<string> ans(n);
map<string,double> P;
for(int i = 0;i < n;i ++){
int k;
string s;
cin >> s >> k;
ans[i] = s;
for(int j = 0;j < k;j ++){
int f;
cin >> f;
Name[s].insert(f);
}
int p = Name[s].size();
P[s] = 1.0 * k / p ;
} sort(ans.begin(), ans.end(),[&](string a,string b){
if(Name[a].size() == Name[b].size()) return P[a] < P[b];
return Name[a].size() > Name[b].size();
}); for(int i = 0;i< 3;i++){
if(i >= ans.size()) cout << "-";
else cout << ans[i] ;
cout << " \n"[i == 2];
} return 0;
}

7-10 重排链表 - SMU 2024 spring 天梯赛自主训练1 (pintia.cn)

模拟链表,链表不是按\(Data\)链接的,要按照给出的起始地址得出链表;

链表可能不是一整条链,有多余节点,最后结果得按链表的最终节点数重排;

#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 st,n;
cin >> st >> n;
vector<PII> L(n);
vector<PII> Num(100100);
for(int i = 0;i < n;i ++){
int x,a,addr;
cin >> addr >> a >> x;
Num[addr] = {a,x};
} int cnt = 0;
while(st != -1){
L[cnt ++] = {Num[st].first,st};
st = Num[st].second;
} for(int i = 0,j = cnt - 1;i <= j;i ++, j --){
if(i == j){
printf("%05d %d -1\n",L[i].second,L[i].first);
return 0;
}
printf("%05d %d %05d\n", L[j].second,L[j].first,L[i].second);
printf("%05d %d ",L[i].second,L[i].first);
if(i == j - 1) printf("-1\n");
else printf("%05d\n",L[j - 1].second);
} return 0;
}

7-11 图着色问题 - SMU 2024 spring 天梯赛自主训练1 (pintia.cn)

所着色一定为\(k\)种;

dfs判断每个点周围是否合法;

#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;
vector g(n + 1, vector<int>());
for (int i = 0; i < m; i ++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
} vector<int> color(n + 1);
vector<bool> vis(n + 1); bool ok = true; auto solve = [&](auto self, int u, int fa, int x) -> void{
vis[u] = true;
for (auto v : g[u]) {
if (color[v] == x) ok = false;
if (v == fa) continue;
if (vis[v]) continue;
self(self, v, u, color[v]);
}
}; int Case;
cin >> Case;
while (Case--) {
ok = true;
set<int> ck;
for (int i = 1; i <= n; i ++) {
cin >> color[i];
ck.insert(color[i]);
}
for (int i = 1; i <= n; i ++)
solve(solve, i, 0, -1);
if (ck.size() != k) ok = false;
cout << (ok ? "Yes" : "No") << '\n';
vector<bool>(n + 1).swap(vis);
} 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;
cin >> n;
set<int> people;
vector<int> fa(10010);
iota(fa.begin(),fa.end(),0); auto find = [&](auto self,int x)->int{
return fa[x] == x ? x : fa[x] = self(self,fa[x]);
}; for(int i = 0;i < n;i ++){
int k,one,u,v;
cin >> k >> one;
people.insert(one);
u = find(find,one);
for(int j = 1;j < k;j ++){
int x;
cin >> x;
people.insert(x);
v = find(find,x);
if(u != v){
fa[v] = u;
}
}
} int All = people.size(), Num = 0;
for(int i = 1;i <= All;i ++)
if(find(find,i) == i) Num ++; cout << All << ' ' << Num << '\n'; int m;
cin >> m;
while(m --){
int u,v;
cin >> u >> v;
u = find(find,u);
v = find(find,v);
if(u != v) cout << "N\n";
else cout << "Y\n";
} return 0;
}

SMU 2024 spring 天梯赛自主训练1的更多相关文章

  1. 2018天梯赛第一次训练题解和ac代码

    随着评讲的进行代码和题解会逐步放上来 2018天梯赛第一次训练 1001 : 进制转换 Time Limit(Common/Java):1000MS/10000MS     Memory Limit: ...

  2. PTA天梯赛训练题L1-064:估值一亿的AI核心代码(字符串模拟)

    Update:smz说regex秒过Orz,yzd记在这里了. 听说今年天梯赛有个烦人的模拟,我便被队友逼着试做一下……一发15,二发20.记一记,要不然枉费我写这么久…… 自己还是代码能力太菜了,校 ...

  3. 【CCCC天梯赛决赛】

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

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

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

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

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

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

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

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

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

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

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

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

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

  10. 山东省ACM多校联盟省赛个人训练第六场 poj 3335 D Rotating Scoreboard

    山东省ACM多校联盟省赛个人训练第六场 D Rotating Scoreboard https://vjudge.net/problem/POJ-3335 时间限制:C/C++ 1秒,其他语言2秒 空 ...

随机推荐

  1. C# 语言在AGI 赛道上能做什么

    自从2022年11月OpenAI正式对外发布ChatGPT依赖,AGI 这条赛道上就挤满了重量级的选手,各大头部公司纷纷下场布局.原本就在机器学习.深度学习领域占据No.1的Python语言更是继续稳 ...

  2. [一句话说iOS]dispatch如何造成死锁

    dispatch_sync执行了两件事:把代码块放入指定线程的任务队列中.堵塞当前线程直到代码块执行结束,如果出现了堵塞的线程和代码块所在的线程为同一线程的话,这个时候代码无法在此线程执行继续下去,即 ...

  3. 模拟用户登录-cookes

    import requests url = 'https://www.xread8.com/user/login.json' headers = { 'User-Agent': 'Mozilla/5. ...

  4. 钉钉应用开发-Python操作钉钉文档(excel版)

    钉钉应用开发-Python操作钉钉文档 一: 服务端SDK下载 服务端SDK下载 - 钉钉开放平台 (dingtalk.com) pip3 install alibabacloud_dingtalk ...

  5. “古剑山”初赛Misc 幸运饼干

    "古剑山"初赛Misc 幸运饼干 考点:Chrome的Cookies解密 赛中思路 bandzip极限压缩hint.jpg后打明文攻击 压缩包密码:sv@1v3z ┌──(root ...

  6. Java-Filter:过滤器请求拦截

    1.概念 web中的过滤器:当访问服务器资源时,过滤器可以将请求拦截下来,完成一些特殊的功能 过滤器的作用: 一般用于完成通用的操作,如:登录验证,统一编码处理,敏感字符过滤 2.快速入门 1.步骤 ...

  7. .NET 9 预览版6发布

    微软发布了 .NET 9 的第 6 个预览版,此版本包括对运行时.SDK..NET MAUI.ASP.NET Core 和 C# 的更新,预览版没有包含太多新的主要功能或特性,因为已接近 .NET 9 ...

  8. Docker自定义网段实现容器间的互访【开发环境中】

    我们都知道docker容器之间是互相隔离的,不能互相访问,但如果有些依赖关系的服务要怎么办呢,所以自定义网段实现容器间的互访. Docker 安装好之后默认会创建三个虚拟网卡,可以使用 docker ...

  9. workman和swoole区别和异同

    swoole是使用C语言实现的socket通信框架,workerman则是使用纯php实现的socket框架,二者进程模型上也存在很多的不同. 先说下swoole的进程模型,看一下以下解析图 mast ...

  10. [oeasy]python0020换行字符_feed_line_lf_反斜杠n_B语言_安徒生童话

    ​ 换行字符 回忆上次内容 struct包可以让我们使用封包格式 把数字封包到字节里 pack函数负责封包 unpack函数负责解封 我们通过封到不同的字节状态 遍历了一次ascii码 ​ 编辑 还是 ...