2023天梯赛个人题解
文章目录
- L1-1 最好的文档
- L1-2 什么是机器学习
- L1-3 程序员买包子
- L1-4 进化论
- L1-5 猜帽子游戏
- L1-6 剪切粘贴
- L1-7 分寝室
- L1-8 谁管谁叫爹
- L2-1 堆宝塔
- L2-2 天梯赛的赛场安排
- L2-3 锦标赛
- L2-4 寻宝图
最后只拿了178分,大佬轻喷。
L1-1 最好的文档
#include<bits/stdc++.h>
using namespace std;void solve(){cout << "Good code is its own best documentation.";
}int main(){solve();return 0;
}
L1-2 什么是机器学习
#include<bits/stdc++.h>
using namespace std;int n, m, k, T, t, _;void solve(){cin >> n >> m;cout << n + m - 16 << endl << n + m - 3 << endl << n + m - 1 << endl << n + m;
}int main(){solve();return 0;
}
L1-3 程序员买包子
#include<bits/stdc++.h>
using namespace std;int n, m, k, T, t, _;void solve(){string s;cin >> n >> s >> m >> k;if(k == n){cout << "mei you mai " << s << " de";return ;}if(k == m){cout << "kan dao le mai " << s << " de";return ; }cout << "wang le zhao mai " << s << " de";
}int main(){solve();return 0;
}
L1-4 进化论
#include<bits/stdc++.h>
using namespace std;int n, m, k, T, t, _;void solve(){cin >> n;for(int i = 1; i <= n; i++){int a, b, c;cin >> a >> b >> c;if(c == a * b){cout << "Lv Yan\n";}else if(c == a + b){cout << "Tu Dou\n";}else cout << "zhe du shi sha ya!\n"; }
}int main(){solve();return 0;
}
L1-5 猜帽子游戏
#include<bits/stdc++.h>
using namespace std;int n, m, k, T, t, _;
int col[110];void solve(){cin >> n;for(int i = 1; i <= n; i++)cin >> col[i];cin >> k;for(int i = 1; i <= k; i++){bool f = 1;int cnt = 0;for(int j = 1; j <= n; j++){int x; cin >> x;if(!x) cnt++;else if(x != col[j]) f = 0;}if(!f || cnt == n) cout << "Ai Ya\n";else cout << "Da Jiang!!!\n";}
}int main(){solve();return 0;
}
L1-6 剪切粘贴
#include<bits/stdc++.h>
using namespace std;int n, m, k, T, t, _;void solve(){string s;cin >> s >> n;s = " " + s;for(int i = 1; i <= n; i++){int l, r; string p1, p2;cin >> l >> r >> p1 >> p2;string t = s.substr(l, r - l + 1);s = s.substr(0, l) + s.substr(r + 1);int sz = p1.size();p1 += p2;int k = s.find(p1);if(k != -1) s = s.substr(0, k + sz) + t + s.substr(k + sz);else s += t;}s = s.substr(1);cout << s;
}int main(){solve();return 0;
}
L1-7 分寝室
#include<bits/stdc++.h>
using namespace std;int n, m, k, T, t, _;
int sum1, sum2;
int ans1 = -1, ans2 = -1;void solve(){cin >> sum1 >> sum2 >> n;vector<int> res1, res2;for(int i = 2; i * i <= sum1; i++){if(sum1 % i == 0){res1.push_back(i);res1.push_back(sum1 / i);}}res1.push_back(1);for(int i = 2; i * i <= sum2; i++){if(sum2 % i == 0){res2.push_back(i);res2.push_back(sum2 / i);}}res2.push_back(1);for(auto i : res1)for(auto j : res2) if(i + j == n){if(ans1 == -1 && ans2 == -1) ans1 = i, ans2 = j;else{int d1 = abs((sum1 / ans1) - (sum2 / ans2));int d2 = abs((sum1 / i) - (sum2 / j));if(d2 < d1) ans1 = i, ans2 = j;}}if(ans1 == -1 && ans2 == -1) cout << "No Solution";else cout << ans1 << ' ' << ans2;
}int main(){solve();return 0;
}
L1-8 谁管谁叫爹
#include<bits/stdc++.h>
using namespace std;int n, m, k, T, t, _;void solve(){cin >> n;for(int i = 1; i <= n; i++){int a, b; cin >> a >> b;bool f = a > b;int na = a, nb = b;int suma = 0, sumb = 0;while(a){suma += a % 10;a /= 10;}while(b){sumb += b % 10;b /= 10;}bool f1 = (na % sumb == 0);bool f2 = (nb % suma == 0);if(f1 && !f2) cout << "A\n";else if(!f1 && f2) cout << "B\n";else cout << (f ? "A" : "B") << endl;}
}int main(){solve();return 0;
}
L2-1 堆宝塔
#include<bits/stdc++.h>
using namespace std;int n, m, k, T, t, _;void solve(){cin >> n;stack<int> s1, s2;int cnt = 0;int mx = 0;for(int i = 1; i <= n; i++){int x; cin >> x;if(!s1.size() || x < s1.top()){s1.push(x);continue;}if(!s2.size() || x > s2.top()){s2.push(x);continue;}cnt++;mx = max(mx, (int)s1.size());while(s1.size()) s1.pop();while(s2.size() && s2.top() > x){s1.push(s2.top());s2.pop();}s1.push(x);}if(s1.size()) cnt++, mx = max(mx, (int)s1.size());if(s2.size()) cnt++, mx = max(mx, (int)s2.size());cout << cnt << ' ' << mx;
}int main(){solve();return 0;
}
L2-2 天梯赛的赛场安排
#include<bits/stdc++.h>
using namespace std;int n, m, k, T, t, _, c;map<int, string> mp; //第i个是哪个学校
map<string, int> Res; //学校需要联系的监考人数void solve(){cin >> n >> c;set<pair<int, int> > S; //{剩余座位数,赛场}set<pair<int, string> > P; //{人数,学校}int sz = 0;int ans = 0;for(int i = 1; i <= n; i++){pair<int, string> res;cin >> res.second >> res.first;mp[i] = res.second;res.first = -res.first; //升序所以加个- 这样就按照人数从大到小排了P.insert(res);}while(P.size()){string s = (*P.begin()).second;int a = -(*P.begin()).first;P.erase(P.begin());if(a >= c){Res[s] += a / c;ans += a / c;a %= c;if(a) P.insert({-a, s});continue;}if(!S.size()){ans++;S.insert({++sz, c - a});}else{bool f = 0;int k, p;for(auto j : S){int x = j.second, pos = j.first;if(x >= a){f = 1;k = x; p = pos;break;}}if(f){S.erase({p, k});k -= a;if(k > 0) S.insert({p, k});}else{ans++;S.insert({++sz, c - a});}}Res[s]++;}for(int i = 1; i <= n; i++)cout << mp[i] << ' ' << Res[mp[i]] << endl;cout << ans;
}int main(){solve();return 0;
}
L2-3 锦标赛
#include<bits/stdc++.h>
using namespace std;#define all(a) a.begin(), a.end()
#define PII pair<int, int>
#define fi first
#define sc second
#define LL long long
#define vi vector<int>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N = 2e5 + 5;
const int M = 2e5 + 5;
const int mod = 998244353;
const int Mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const LL inff = 0x3f3f3f3f3f3f3f3f;
int n, m, k, t, T, _;int ans[1 << 19], a[20][1 << 19], pos[20][1 << 19];void solve(){cin >> k;for(int i = 1; i <= k; i++)for(int j = 1; j <= 1 << (k - i); j++){cin >> a[i][j];if(i == 1) ans[(j << 1) - 1] = a[i][j], pos[i][j] = j << 1;else{int mx = max(a[i][j], max(a[i - 1][j << 1], a[i - 1][(j << 1) - 1]));if(a[i][j] < a[i - 1][j << 1] && a[i][j] < a[i - 1][(j << 1) - 1]){cout << "No Solution\n";return ;}else if(a[i][j] >= a[i - 1][j << 1]){ans[pos[i - 1][j << 1]] = a[i][j];pos[i][j] = pos[i - 1][(j << 1) - 1];}else{ans[pos[i - 1][(j << 1) - 1]] = a[i][j];pos[i][j] = pos[i - 1][j << 1];}a[i][j] = mx;}}int mx; cin >> mx;if(a[k][1] <= mx) ans[pos[k][1]] = mx;else{cout << "No Solution\n";return ;}for(int i = 1; i <= 1 << k; i++)cout << ans[i] << " \n"[i == 1 << k];
}int main(){//for(cin >> _; _--;)solve();return 0;
}
L2-4 寻宝图
#include<bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
int n, m, k, T, t, _;
vector<vector<char> > aa;
vector<vector<bool> > vis;
int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int cnt, ans;bool check(int i, int j){if(i < 1 || i > n || j < 1 || j > m) return false;if(aa[i][j] == '0' || vis[i][j]) return false;return true;
}void bfs(int i, int j){queue<PII> q;q.push({i, j});vis[i][j] = 1;bool f = 0;while(q.size()){int x = q.front().first, y = q.front().second;q.pop();if(aa[x][y] != '1') f = 1;for(int i = 0; i < 4; i++){int dx = x + dir[i][0], dy = y + dir[i][1];if(!check(dx, dy)) continue;q.push({dx, dy});vis[dx][dy] = 1;}}if(f) ans ++;
}void solve(){cin >> n >> m;vector<vector<char> > a(n + 1, vector<char> (m + 1));vector<vector<bool> > v(n + 1, vector<bool> (m + 1));for(int i = 1; i <= n; i++)for(int j = 1; j <= m; j++)cin >> a[i][j];aa = a;vis = v;for(int i = 1; i <= n; i++)for(int j = 1; j <= m; j++)if(!vis[i][j] && aa[i][j] != '0') bfs(i, j), cnt++;cout << cnt << ' ' << ans;
}int main(){solve();return 0;
}
2023天梯赛个人题解相关推荐
- cccc-gplt 团体程序设计天梯赛JAVA题解
1. 前言 大多是想用java解的,有些题java会超时就换成了c++ Github 天梯赛 2. 目录 编号 标题 题解 分类 L1-001 Hello, World Java 水题 L1-002 ...
- SWPU 2021年团队程序设计天梯赛选拔赛 题解
补题场链接:https://pintia.cn/problem-sets/1373141720280027136 本次选拔赛除后三题以外,其余的题目难度都不是很大,简单筛选一下大家的基础.请大家这段时 ...
- 2021年团体程序设计天梯赛-总决赛题解
L2-2 病毒溯源 L2-4 哲哲打游戏 L3-2 还原文件 L1-1 人与神 (5 分) 跨界大神 L. Peter Deutsch 有一句名言:"To iterate is human, ...
- 2021天梯赛L2题解全集
L2-037 包装机 (25 分) 其实就是个模拟,按照题目意思写下去吧,也不知道为什么比赛的时候一直只能拿20分(用char数组+ int变量模拟栈) 赛后直接用栈写的一发满分就很奇怪...主要是题 ...
- PTA程序设计天梯赛 L2题解报告(40/40)
目录 L2-001 紧急救援 (25 分) L2-002 链表去重 (25 分) L2-003 月饼 (25 分) L2-004 这是二叉搜索树吗? L2-005 集合相似度 (25 分) L2-00 ...
- 2021CCCC天梯赛L2题解
L2第一题:包装机 大体题意是给筐和轨道的容量,然后经过一系列操作后输出流水线上的物品.轨道的操作就像队列,筐的操作符合栈的特性.理解题之后我们就知道了,这是一道模拟送分题,开始加速操作他把. #in ...
- PAT : 团体程序设计天梯赛-练习集L1 个人题解
另把天梯赛所有题解内容全部打包成了一个文档,可以自行下载:https://download.csdn.net/download/daixinliangwyx/11170075 L1-001 Hello ...
- 2022 CCCC 团体程序设计天梯赛(个人题解)
L1-1 今天我要赢(5分) #include<bits/stdc++.h> using namespace std; int main(){cout<<"I'm g ...
- PAT : 团体程序设计天梯赛-练习集 L3 答案即比赛技巧
知识点分类(23): 1.搜索模拟(5):BFS,DFS,最短路,路径打印 2.计算几何(5):找规律,斜率计算,极角排序,三角形面积,三点共线,凸包 3.数据结构(5):栈,并查集,二叉树,堆,线段 ...
最新文章
- Java中return结束循环,Java中break、continue、return在for循环中的使用
- 深入浅出python机器学习_3.3.1_对数据集进行分析
- SVM(support vector machine)支持向量机原理详解
- youcans 的 OpenCV 学习课—2.图像读取与显示
- 信息学奥赛C++语言:For循环输出
- C#开发笔记之20-如何用C#深克隆一个对象(优雅方案)?
- 计算机辅助翻译入门试题,2011级计算机辅助翻译考试试题纸(A卷)
- AndroidStudio安卓原生开发_Intent传过来的值会自动变化_太奇怪了_你碰见过嘛_Http并发引起的问题?_可通过静态变量传值的方式解决---Android原生开发工作笔记130
- 人脸关键点: DCNN-Deep Convolutional Network Cascade for Facial Point Detection
- 【OpenCV】图像线性混合
- spring3.1.1与commons-dbcp1.2的冲突?
- 基于企业微信和钉钉的工资条发送工具 - 工资条帮
- matlab dsolve函数构造微分方程
- 一个老程序员的忠告:千万不要一辈子靠技术生存
- 设置windows补丁自动更新指向固定服务器
- PAT --- 1068.万绿丛中一点红 (20 分)
- MIPS/RISC-V ALU设计
- 卸载软件-Uninstall Tool(无残留)
- 会声会影制作MV(带歌词字幕)的方法
- Python 字符串常见的语句,和练习题,字符串练习题 Python 切片函数修饰符 #精度和进制Python 字符串一些语句练课件练习题
热门文章
- GMT5在linux下的中文支持
- 软件测试面试题汇总,【全网最全整理】
- cmi编码实验_CMI码型变换试验
- 梅宫主:创业小白精准引流之——布局自动化引流系统三大绝招!
- 100个人围成一圈c语言,C语言 约瑟夫圈问题:N个人围成一圈,从第一个人开始按顺序报数并编号1,2,3,……N,然后开始从第一个人转圈报数,凡是报到3的退出圈子。则剩下的最后一个人编号是多少。...
- linux strsep字符串分割
- 使用props传递数据
- 使用Java IO流实现网页数据爬取(一)
- 活动(Activity)
- 林氏木业亮相广州建博会,迎接全屋定制新风口