码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 2024蓝桥杯每日一题(双指针)


    一、第一题:牛的学术圈

     

    解题思路:双指针+贪心
         仔细思考可以知道,写一篇综述最多在原来的H指数的基础上+1,所以基本方法可以是先求出原始的H指数,然后分类讨论怎么样提升H指数。

    【Python程序代码】

    1. n,l = map(int,input().split())
    2. a = list(map(int,input().split()))
    3. a.sort()
    4. res,suml,sumr = 0,0,0
    5. for i in range(n):
    6. sumr = n-i
    7. if a[i]>sumr:
    8. if i==0:break
    9. if a[i-1]+1>=sumr+1 and l>=1:
    10. sumr+=1
    11. break
    12. break
    13. if a[i]==sumr:
    14. j,c = i,1
    15. if i == 0: break
    16. while j+1and a[j+1]==a[i]:
    17. j += 1
    18. c += 1
    19. if a[i-1]==a[i] and l>=c+1:
    20. sumr+=1
    21. break
    22. if l==0 and a[n-1]==0:print(0)
    23. else:print(sumr)

    二、第二题:最长连续不重复子序列

    思路:双指针
            双指针模板题

    【Python程序代码】

    1. n = int(input())
    2. a = [0] + list(map(int,input().split()))
    3. mp = [0]*(100010)
    4. res,j=1,1
    5. for i in range(1,n+1):
    6. if mp[a[i]]:
    7. res = max(res,i-j)
    8. while a[j]!=a[i]:
    9. mp[a[j]]-=1
    10. j +=1
    11. j += 1
    12. else:
    13. mp[a[i]]+=1
    14. res = max(res,i-j+1)
    15. print(res)

    三、第三题: 数组元素的目标和

    解题思路:双指针
            双指针模板题

    【Python程序代码】

    1. n,m,x = map(int,input().split())
    2. a = list(map(int,input().split()))
    3. b = list(map(int,input().split()))
    4. j = m-1
    5. res = []
    6. for i in range(n):
    7. if a[i]+b[j]continue
    8. if a[i]+b[j]==x:
    9. res.append((i,j))
    10. continue
    11. if a[i]+b[j]>x:
    12. while j>0 and a[i]+b[j]>=x:
    13. if a[i]+b[j]==x:
    14. res.append((i,j))
    15. j -= 1
    16. for i in res:
    17. print(i[0],i[1])

    四、第四题: 判断子序列

    解题思路:双指针
            双指针模板题

    【Python程序代码】

    1. n,m = map(int,input().split())
    2. a = list(map(int,input().split()))
    3. b = list(map(int,input().split()))
    4. j = 0
    5. for i in range(m):
    6. if j==n:break
    7. if b[i]==a[j]:
    8. j += 1
    9. if j==n:print("Yes")
    10. else:print("No")

    五、第五题: 日志统计

     解题思路:双指针+滑动窗口
            双指针+滑动窗口模板题

    【Python程序代码】

    1. from collections import defaultdict
    2. n,d,k = map(int,input().split())
    3. mp = defaultdict(int)
    4. a,res = [],[]
    5. for i in range(n):
    6. ts,id = map(int,input().split())
    7. a.append([ts,id])
    8. a.sort()
    9. j,pret = 0,0
    10. for i in range(n):
    11. teps,tepd = a[i]
    12. if teps - a[j][0]>=d:
    13. while teps - a[j][0]>=d:
    14. mp[a[j][1]]-=1
    15. j += 1
    16. pret = a[j][0]
    17. mp[tepd] += 1
    18. if mp[tepd]>=k:
    19. res.append(tepd)
    20. res = list(set(res))
    21. res.sort()
    22. for i in res:print(i)


     

  • 相关阅读:
    多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
    【Pytorch】进阶学习:深入解析 sklearn.metrics 中的 classification_report 函数---分类性能评估的利器
    Android音频子系统(十一)------耳机返听(耳返)原理实现
    OpenHarmony实战开发-多设备自适应能力
    【ansible】自动化运维ansible之playbook剧本编写与运行
    MyBatis 源码分析之 SqlSessionFactory 创建
    阿里发布大模型发布图结构长文本处理智能体,超越GPT-4-128k
    前端性能精进(六)——网络
    【C++上层应用】5. 文件和流
    Transmodeler中的路边停车,让车停进去的参数在哪儿设置?
  • 原文地址:https://blog.csdn.net/w2563216521/article/details/136586229
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | 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号