文章目录

  • 概要
  • L1-089 最好的文档 5
  • L1-090 什么是机器学习 5
  • L1-091 程序员买包子 10
  • L1-092 进化论 10
  • L1-093 猜帽子游戏 15
  • L1-094 剪切粘贴 15
  • L1-095 分寝室 20
  • L1-096 谁管谁叫爹 20
  • L2-045 堆宝塔 25
  • L2-046 天梯赛的赛场安排
  • L2-047 锦标赛 25
  • L2-048 寻宝图 25
  • L3-035 完美树(骗分16)
  • 参考资料

概要

L1部分:L1-089~L1-096
L2部分:L2-045~L2-048
L3部分:L3-033~L3-036

L1-089 最好的文档 5

#include<bits/stdc++.h>
using namespace std;
int main(){cout<<"Good code is its own best documentation.\n";return 0;
}

L1-090 什么是机器学习 5

#include<bits/stdc++.h>
using namespace std;
int main(){int a, b;  cin>>a>>b;int c = a+b;cout<<c-16<<"\n"<<c-3<<"\n"<<c-1<<"\n"<<c<<"\n";return 0;
}

L1-091 程序员买包子 10

#include<bits/stdc++.h>
using namespace std;
int main(){int n, m, k;  string x; cin>>n>>x>>m>>k;if(k==n){cout<<"mei you mai "<<x<<" de\n";}else if(k==m){cout<<"kan dao le mai "<<x<<" de\n";}else{cout<<"wang le zhao mai "<<x<<" de"<<"\n";}return 0;
}

L1-092 进化论 10

#include<bits/stdc++.h>
using namespace std;
int main(){int n;  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";}}return 0;
}

L1-093 猜帽子游戏 15

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int a[maxn];
int main(){int n;  cin>>n;for(int i = 1; i <= n; i++){cin>>a[i];}int k;  cin>>k;while(k--){int ok = 0, ok2 = 1;for(int i = 1; i <= n; i++){int x;  cin>>x;if(x==0)continue;else if(x==a[i]){ok = 1;}else{ok2 = 0;}}if(ok2==1 && ok==1){cout<<"Da Jiang!!!\n";}else{cout<<"Ai Ya\n";}}return 0;
}

L1-094 剪切粘贴 15

#include<bits/stdc++.h>
using namespace std;
int main(){string s;  cin>>s;int T;  cin>>T;while(T--){int x, y;  string a, b;  cin>>x>>y>>a>>b;string t = s.substr(x-1, y-x+1);s.erase(x-1,y-x+1);int cur = 0;int ok = 1;while(s.find(a,cur) != s.npos && cur < s.size()){int p = s.find(a,cur);string tt = s.substr(p+a.size(),b.size());if(tt == b){s.insert(p+a.size(),t);ok = 0;break;}else{cur++;}}if(s.find(a, cur) == s.npos && ok == 1){s.insert(s.size(), t);}}cout<<s<<"\n";return 0;
}

L1-095 分寝室 20

#include<bits/stdc++.h>
using namespace std;
int main(){int x, y, n;  cin>>x>>y>>n;int xx = -1, yy = -1, rs = 1e5+10;int zx = 0, zy = 0;for(int i = 1; i < n; i++){int j = n-i;if(x%i!=0 || y%j!=0)continue;int xi = x/i, yj = y/j;if(xi==1 || yj==1)continue;if(abs(xi-yj) < rs){xx = xi;yy = yj;zx = i;zy = j;rs = abs(xi-yj);}}if(xx!=-1)cout<<zx<<" "<<zy<<"\n";else cout<<"No Solution\n";return 0;
}

L1-096 谁管谁叫爹 20

#include<bits/stdc++.h>
using namespace std;
int get(int x){int res = 0;while(x){res += x%10;x /= 10;}return res;
}
int main(){int n;  cin>>n;while(n--){int na, nb;  cin>>na>>nb;int sa = get(na), sb = get(nb);if(na%sb==0&&nb%sa==0){if(na > nb){cout<<"A\n";}else{cout<<"B\n";}}else if(na%sb==0)cout<<"A\n";else if(nb%sa==0)cout<<"B\n";else if(na > nb){cout<<"A\n";}else{cout<<"B\n";}}return 0;
}

L2-045 堆宝塔 25

//思路:
//看到堆盘子想到水杯/栈 /(汉诺塔/递归,并没有)之类的东西,按题意无脑模拟即可
#include<bits/stdc++.h>
using namespace std;
int main(){int n;  cin>>n;stack<int>a, b;int cnt = 0, mx = 0;while(n--){int x;  cin>>x;if(a.empty() || x<a.top()){a.push(x);}else{if(b.empty() || x>b.top()){b.push(x);}else{mx = max(mx, (int)a.size());while(!a.empty())a.pop();cnt++;while(!b.empty() && b.top()>x){a.push(b.top());b.pop();}a.push(x);}}}if(a.size()!= 0)cnt++;if(b.size()!= 0)cnt++;mx = max(mx, (int)a.size());cout<<cnt<<" "<<mx<<"\n";return 0;
}

L2-046 天梯赛的赛场安排

//思路:
//按题意模拟即可,注意细节点比较多,每一轮对当前未安排的人数最多的学校进行处理,只处理一个考场,然后剩余人数是要放回去的。
//最开始的找人数最多可以重载优先队列,找编号最小的和新开考场其实注意到数组范围不大,其实可以开个数组for。
//好久没写代码了,一下子没想到开数组,也忘记怎么打重载了,所以就乱搞了一波,强行暴力多for了一下。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5050;
string sc[maxn];
int num[maxn], rs[maxn];
int main(){int n, c;  cin>>n>>c;priority_queue<pair<int,int>>q2;for(int i = 1; i <= n; i++){cin>>sc[i]>>num[i];q2.push({num[i], i});}int cnt = 0;int tot = 0;priority_queue<pair<int,int>>q;int xxx = 0;while(q2.size()){int nm = q2.top().first;int id = q2.top().second;  q2.pop();if(nm > c){rs[id]++;cnt++;nm -= c;q2.push({nm,id});continue;}if(nm != 0){if(!q.empty() && q.top().first >= nm){vector<pair<int,int>>vc;while(!q.empty() && q.top().first >= nm){vc.push_back(q.top()); q.pop();}int t = vc.back().first; int id2 = vc.back().second;t -= nm;rs[id]++;if(t != 0)q.push({t, id});for(int i = 0; i < vc.size()-1; i++){q.push(vc[i]);}}else{q.push({c-nm, ++tot});rs[id]++;cnt++;}}}for(int i = 1; i <= n; i++){cout<<sc[i]<<" "<<rs[i]<<"\n";}cout<<cnt<<"\n";return 0;
}

L2-047 锦标赛 25

//题意:2^k个人两两比赛,最后剩1个。给出第i轮第j场的失败者,求最开始的所有人顺序。
//思路:完美二叉树,底层一半的值确定了,然后往上走一层,如果当前值比前一层对应位置的某个值大,那么就可以加入答案中,否则加无解了。
//数组维护上一层每个节点在答案中的位置(尚未被填入值的),然后从底往上走依次把值填进去即可。
#include<bits/stdc++.h>
using namespace std;
#define lch (j<<1)
#define rch (j<<1|1)const int maxv = 50, maxn = (1<<20);
int a[maxv][maxn], o[maxv][maxn]; //第i层第j个的能力,以及兄弟节点在答案中的位置
int res[maxn];int main(){int k;  cin>>k;int ok = 1;for(int i = 1; i <= k; i++){int n = 1<<(k-i);for(int j = 0; j < n; j++){  //枚举每一层cin>>a[i][j];if(i==1){res[lch] = a[i][j];  o[i][j] = rch;continue;}int mx = max(a[i][j], max(a[i-1][lch], a[i-1][rch]));if(a[i][j] < a[i-1][lch] && a[i][j] < a[i-1][rch]){ok = 0;break;}else if(a[i][j] >= a[i-1][lch]){ //如果当前是胜者, 就放到另一个位置res[o[i-1][lch]] = a[i][j];o[i][j] = o[i-1][rch]; }else{res[o[i-1][rch]] = a[i][j];o[i][j] = o[i-1][lch];}  a[i][j] = mx;  //记录子树最大值}}int w;   cin>>w;if(a[k][0] <= w) res[o[k][0]] = w; else ok = 0;if(ok==0){ cout<<"No Solution\n"; return 0; }for(int i = 0; i < (1<<k); i++){cout<<res[i]<<" \n"[i==(1<<k)];}return 0;
}

L2-048 寻宝图 25

//题意:Floodfill 例题,找联通块。
//岛屿的个数:dfs找有多少个联通块即可,注意1e5x1e5开不下bool/int数组和判重,可以用变长string,然后走过一个点就直接改掉
//宝藏岛屿:注意特判刚进去的那个点是不是宝藏,没判断的话是15分
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int n, m;
string a[maxn];
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int ok = 0;
void dfs(int x, int y){if(a[x][y]!='0' && a[x][y] != '1')ok = 1;for(int i = 0; i < 4; i++){int nx = x+dx[i], ny = y+dy[i];if(nx<=0||nx>n || ny<=0 || ny > m)continue;if(a[nx][ny]=='0')continue;if(a[nx][ny]!='1')ok = 1;a[nx][ny] = '0';dfs(nx, ny);}
}
int main(){cin>>n>>m;for(int i = 1; i <= n; i++) {cin>>a[i];a[i] = "0"+a[i];}int cnt = 0, res = 0;for(int i = 1; i <= n; i++){for(int j = 1; j <= m; j++){if(a[i][j]!='0'){ok = 0;dfs(i,j);cnt++;if(ok==1)res++;}}}cout<<cnt<<" "<<res<<"\n";return 0;
}

L3-035 完美树(骗分16)

//骗分:最后只输出一个数字,暴力从1开始枚举看看能不能骗分
//发现0有1分,20有15分。 然后试试限一下n的范围把两个点都骗进去。
#include<bits/stdc++.h>
using namespace std;int main(){int n;  cin>>n;if(n<10)cout<<"0";//1分else cout<<"20";   //15分return 0;
}

参考资料

官方题解:链接

【2023团体程序设计天梯赛CCCC】GPLT2023,L1~L2部分(PTA,L1-089~L1-096,L2-045~L2-048)题解代码复盘相关推荐

  1. 2023团体程序设计天梯赛--正式赛

    L1-1 最好的文档 有一位软件工程师说过一句很有道理的话:"Good code is its own best documentation."(好代码本身就是最好的文档).本题就 ...

  2. 2021第六届GPLT 团体程序设计天梯赛CCCC 个人题解

    目录 L1-1 人与神 Code L1-2 两小时学完C语言 Code L1-3 强迫症 思路 Code L1-4 降价提醒机器人 Code L1-5 大笨钟的心情 思路 Code L1-6 吉老师的 ...

  3. 【CCCC】PAT : 团体程序设计天梯赛-练习集 L1 答案

    [CCCC]PAT : 团体程序设计天梯赛-练习集 L1 答案 鉴定完毕,全部水题 ヾ(•ω•`)o 标号 标题 分数 通过数 提交数 通过率 L1-001 Hello World 5 46779 1 ...

  4. 【CCCC】PAT : 团体程序设计天梯赛-练习集 L2 答案,题解,附代码

    [CCCC]PAT : 团体程序设计天梯赛-练习集 L2 答案 鉴定完毕,全部水题 ヾ(•ω•`)o 知识点分类(32): 1.树锯结构(9):二叉树的存储,编号,遍历顺序转换,求深度,底层节点,从底 ...

  5. 第八届cccc团体程序设计天梯赛——个人参赛总结——无代码纯粹的参赛总结

    第八届cccc团体程序设计天梯赛--个人参赛总结--无代码纯粹的参赛总结 目录 第八届cccc团体程序设计天梯赛--个人参赛总结--无代码纯粹的参赛总结 引言~介绍一下cccc天梯赛(==选读==) ...

  6. 【CCCC】PAT : 团体程序设计天梯赛-练习集 L3 答案(01-23)

    [CCCC]PAT : 团体程序设计天梯赛-练习集 L3 答案 顶着满课,整整一星期,终于咕完了.(:´д`)ゞ 知识点分类(23): 1.搜索模拟(5):BFS,DFS,最短路,路径打印 2.计算几 ...

  7. 2023年团体程序设计天梯赛

    2020年团体程序设计天梯赛 PTA L2-034 口罩发放 (25 分) PTA L2-036 网红点打卡攻略 (25 分) 2021年团体程序设计天梯赛 PTA L1-078 吉老师的回归 (15 ...

  8. 2020年团体程序设计天梯赛L1题目集(题目+代码)

    2020年11月团体程序设计天梯赛 第一次参加天梯赛,除了在门口冻得瑟瑟发抖,还有按不动的shift之外一切都还好- tip:不知道啥原因代码上基本没有注释,希望dalao们不要介意~ L1-1 嫑废 ...

  9. 团体程序设计天梯赛-L2组

    团体程序设计天梯赛-L2组 -------------------------------------------------------------------------------- 题目传送门 ...

最新文章

  1. Map集合中value()方法与keySet()、entrySet()区别 ——转载
  2. Day12 Java异常处理与程序调试
  3. HLS—AXI4-Lite Interface
  4. 将AspectJ与NetBeans平台开发集成
  5. 基础编程题目集 6-13 折半查找 (15 分)
  6. (转)Spring Boot 2 (三):Spring Boot 开源软件都有哪些?
  7. iOS开源App整理
  8. wh计算公式_功率计算公式
  9. 数据分析师到底是做什么的?写Python或SQL语句?
  10. LOGO特训营 第一节 鉴别Logo与Logo设计思路
  11. 2018年需要记住的5个区块链事实
  12. 怎样才能成为一名优秀的高薪程序员?
  13. Android Error while Launching activity
  14. 2,JESD204为什么值得关注?
  15. 同质化游戏做出不同点在于背景音乐
  16. Deepin v20安装过程详细步骤
  17. 重复性工作再也不用做啦?机器人自动化迎难而上
  18. php简单富文本,JavaScript_Javascript实现简单的富文本编辑器附演示,复制代码 代码如下: span styl - phpStudy...
  19. Vue响应式更新原理(个人总结)
  20. 金融服务(银行证券机构方向)etl批量作业集群统一调度平台搭建

热门文章

  1. 零基础python爬虫基础之王者荣耀图片下载(超级简单)
  2. 靶向药物丨艾美捷西妥昔单抗Cetuximab方案
  3. 【揭秘】美团外卖日单量破1600万背后的“超级大脑”之订单分配
  4. 创文明城市在路上,信息报送有高招
  5. 前端加密 后端Java解密
  6. 十年前你绝对没有看懂的《大话西游》.
  7. 安装Visio + Windows Installer 与即点即用版本冲突 + 卸载Office + 重装Office
  8. M480 EMAC驱动02-IP101G测试
  9. 单片机驱动直流电机c语言代码,单片机驱动带编码器直流电机 源程序
  10. 何洛洛高考成绩查询2021,2021高考查分时间表 什么时候查成绩