码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 2022团体程序设计天梯赛L1


    目录(这个链接有点牛马,不建议点,给我整无语了)

    L1-081 今天我要赢

    Question:        Solve:         AC Code: ​​​​​​​

    L1-082 种钻石

    Question:        Solve:         AC Code: 

    L1-083 谁能进图书馆

    Question:        Solve:         AC Code: 

    L1-084 拯救外星人

    Question:        Solve:         AC Code: 

    L1-085 试试手气

    Question:        Solve:        AC Code: 

    L1-086 斯德哥尔摩火车上的题

    Question:        Solve:        AC Code: 

    L1-087 机工士姆斯塔迪奥

    Question:        Solve:

    AC Code(元素标记暴力):AC Code(行列标记计算) :

    L1-088 静静的推荐​​​​​​​

    Question:        Solve:         AC Code: ​​​​​​​

    Notice:天梯赛格式控制是首要的


    ​​​​​​​​​​​​​​L1-081 今天我要赢

    Question:

    Solve: 

    单纯输出,不加掩饰,没有比python更适合写这道题的语言~

    AC Code: 

    1. print("I'm gonna win! Today!")
    2. print("2022-04-23")


    L1-082 种钻石

    Question:

    Solve: 

    直接向下取整就行,所以也用python写了

    AC Code: 

    1. a,b = map(int, input().split(' '))
    2. print(a // b) #向下取整


    L1-083 谁能进图书馆

    Question:

    Solve: 

    没什么好办法,按照逻辑顺序设条件就行

    AC Code: 

    1. #include <iostream>
    2. using namespace std;
    3. int a, b, q1, q2;
    4. int main(void)
    5. {
    6. cin >>a >>b >>q1 >>q2;
    7. //均大于
    8. if(q1 >= a && q2 >= a){
    9. printf("%d-Y %d-Y\n", q1, q2);
    10. printf("huan ying ru guan");
    11. //均小于
    12. }else if(q1 < a && q2 < a){
    13. printf("%d-N %d-N\n", q1, q2);
    14. printf("zhang da zai lai ba");
    15. //可陪同1
    16. }else if(q1 >= b && q2 < a){
    17. printf("%d-Y %d-Y\n", q1, q2);
    18. printf("qing 1 zhao gu hao 2");
    19. //可陪同2
    20. }else if(q1 < a && q2 >= b){
    21. printf("%d-Y %d-Y\n", q1, q2);
    22. printf("qing 2 zhao gu hao 1");
    23. //1可入(条件覆盖省略)
    24. }else if(q2 < a){
    25. printf("%d-Y %d-N\n", q1, q2);
    26. printf("1: huan ying ru guan");
    27. //2可入
    28. }else{
    29. printf("%d-N %d-Y\n", q1, q2);
    30. printf("2: huan ying ru guan");
    31. }
    32. return 0;
    33. }


    L1-084 拯救外星人

    Question:

     Solve: 

    求阶乘太基础了吧

    AC Code: 

    1. #include <iostream>
    2. using namespace std;
    3. int res = 1, a, b;
    4. int main(void)
    5. {
    6. cin >>a >>b;
    7. a += b;
    8. for(int i = 2; i <= a; i++){
    9. res *= i;
    10. }
    11. cout <<res;
    12. return 0;
    13. }


    L1-085 试试手气

    Question:

     Solve:

    这个题每个骰子都是从6点到1点,只不过要避开初始点数

    所以:

    投掷次数 <= 6 - 初始点数(正常降序,结果为 6 - n + 1)

    投掷次数  >  6 - 初始点数(需要避开,结果为 6 - n)

    AC Code: 

    1. #include <iostream>
    2. using namespace std;
    3. int a[7], n;
    4. int main(void)
    5. {
    6. for(int i = 1; i <= 6; i++) cin >>a[i];
    7. cin >>n;
    8. for(int i = 1; i <= 6; i++){
    9. if(6 - n >= a[i])
    10. cout <<7 - n;
    11. else
    12. cout <<6 - n;
    13. if(i != 6) cout <<" ";
    14. }
    15. return 0;
    16. }


    L1-086 斯德哥尔摩火车上的题

    Question:

    Solve:

    直接模拟函数即可

    AC Code: 

    1. #include <iostream>
    2. #include <cstring>
    3. using namespace std;
    4. string s1, s2;
    5. string solve(string s){
    6. string e = "";
    7. for (int i = 1; i < s.length(); i++) {
    8. if (s[i] % 2 == s[i-1] % 2) {
    9. e += max(s[i], s[i-1]);
    10. }
    11. }
    12. return e;
    13. }
    14. int main(void)
    15. {
    16. cin >>s1 >>s2;
    17. string a = solve(s1);
    18. string b = solve(s2);
    19. if(a == b) cout <<a;
    20. else
    21. cout <<a <<endl <<b;
    22. return 0;
    23. }


    L1-087 机工士姆斯塔迪奥

    Question:

    Solve:

    这个题可以暴力,也可以用数学推导

    不过暴力是建立在vector上的,比赛时候直接就过了,如果用数组就TLE了

    AC Code(元素标记暴力): 

    1. #include <bits/stdc++.h>
    2. using namespace std;
    3. vector<int>v[100010];
    4. int main(void)
    5. {
    6. int n, m, q;
    7. scanf("%d%d%d", &n, &m, &q);
    8. //初始化,向量全部置0
    9. for(int i = 1; i <= n; i++)
    10. for(int j = 0; j <= m; j++)
    11. v[i].push_back(0);
    12. //修改
    13. while(q--){
    14. int t, c;
    15. scanf("%d%d", &t, &c);
    16. if(t){
    17. for(int i = 1; i <= n; i++)
    18. v[i][c] = 1;
    19. }else{
    20. for(int i = 1; i <= m; i++)
    21. v[c][i] = 1;
    22. }
    23. }
    24. //计数输出
    25. int res = 0;
    26. for(int i = 1; i <= n; i++)
    27. for(int j = 1; j <= m; j++)
    28. if(!v[i][j]) res++;
    29. cout <<res;
    30. return 0;
    31. }

    AC Code(行列标记计算) :

    1. #include <iostream>
    2. #include <cstring>
    3. #define N 100000
    4. using namespace std;
    5. typedef long long ll;
    6. int row = 0, col = 0; //标记有多少行和列被选中
    7. bool ro[N+1], co[N+1]; //标记被选中的行和列
    8. int n, m, q;
    9. int main(void)
    10. {
    11. cin >>n >>m >>q;
    12. ll res = n * m;
    13. //初始化
    14. for(int i = 1; i <= max(n, m); i++)
    15. ro[i] = co[i] = false;
    16. //修改
    17. for(int i = 1; i <= q; i++){
    18. int t, c; cin >>t >>c;
    19. if(t){ //选择列
    20. if(co[c]) continue; //已经选择,直接跳过
    21. col++; co[c] = true;
    22. res -= (n - row);
    23. }else{ //选择行
    24. if(ro[c]) continue;
    25. row++; ro[c] = true;
    26. res -= (m - col);
    27. }
    28. }
    29. cout <<res;
    30. return 0;
    31. }


    L1-088 静静的推荐​​​​​​​

    Question:

    Solve: 

    这个题在毫不知情的情况下很容易往 dp 上想,n 阶最长上升子序列?好像也行

    但其实只需要把握两个点:

    1. PAT成绩达到且天梯赛在 175 分以上的一定可以被推荐,因为这样的选手可以被插在任意一组推荐之中

    2. PAT成绩不够但天梯赛在 175 分以上的 同分数最多能选 k 个 ,因为每次推荐都能带走一个

    AC Code: 

    1. #include <iostream>
    2. #include <cstring>
    3. using namespace std;
    4. int n, k, s, cnt[291];
    5. int t, p, res = 0;
    6. int main(void)
    7. {
    8. memset(cnt, 0, sizeof(cnt));
    9. cin >>n >>k >>s;
    10. for(int i = 1; i <= n; i++){
    11. cin >>t >>p;
    12. //小于175直接跳过
    13. if(t < 175) continue;
    14. //PAT分数达到,一定可进
    15. if(p >= s){ res++; continue; }
    16. //PAT分数不够,同分数不能超过k
    17. if(cnt[t] < k){ cnt[t]++, res++; }
    18. }
    19. cout <<res;
    20. return 0;
    21. }

  • 相关阅读:
    我们写的代码是如何一步步变成可执行程序(.EXE)的?
    抖音矩阵系统源码独立部署,抖音SEO源码定制。
    git常用语句
    Spring Security 中的 RememberMe 登录,so easy!
    使用flask实现一个简单的代理服务
    基于ssm服装购物系统
    vben-admin 学习记录
    Sarcasm detection论文解析 |使用 BERT 进行中间任务迁移学习的刺检测
    树莓派4B_OpenCv学习笔记21:OpenCV_haar人脸识别
    正则表达式——2.正则表达式的基础
  • 原文地址:https://blog.csdn.net/qq_59700927/article/details/125389102
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号