• 第十四届蓝桥杯模拟赛(第二期)


    写在前面 

    1. 包含本次模拟赛的10道题题解
    2. 能过样例,应该可以AC
    3. 若有错误,欢迎评论区指出
    4. 有疑问可私信我哈🫰🏻

     


    77447c960dcf4dfbacebba03dd08455f.png

    从2023开始暴力枚举每一个数,直到找到正确答案 

    1. start = 2022
    2. def check(num) :
    3. t = str(bin(num))
    4. if t[-6:] == '000000' : return True
    5. return False
    6. while 1 :
    7. start += 1
    8. if check(start) : print(start) ; break

    096298de6c5f4620a4db196f59a654e0.png

    使用Python自带的datetime库统计一共多少天 

    1. import datetime
    2. start = datetime.date(1949,10,1)
    3. end = datetime.date(2022,1,1)
    4. diff = datetime.timedelta(1)
    5. ans = 0
    6. while start < end :
    7. ans += 1
    8. start += diff
    9. print(ans)

     

    f75a435af3b34324a24b1ce45c6dd6e3.png

    从10开始枚举直到找到正确答案

    1. start = 10
    2. def check(num) :
    3. t = int(str(num),16)
    4. if t % num == 0 : print(num,t) ; return True
    5. return False
    6. while 1 :
    7. if check(start) : print(start) ; break
    8. start += 1

     

    48d20bc480d445848869174050c845c7.png

    动态规划,dp[i][j]代表走到第i行,第j列的最大值是多少,它是由左边的前一个元素dp[i][j-1]和上边的dp[i-1][j] 两者之间的最大值+原数组第i行,第j列的值相加 更新而来的。

    1. s = "174094882455171152761423221685761892795431233411387427793198\
    2. 650286024865090061389344606618496378829135984076361542097372\
    3. 601657541200146071777733599818266038012509478351201640618984\
    4. 143988087783837107349651099683484992553337438088068198972282\
    5. 890781586124258626539246182119762952003918195325258677229419\
    6. 698255491250839396799769357665825441616335532825361862146291\
    7. 503649293440596342887581257444442930778730382520372975343211\
    8. 325351222640703400531067500454956482168314849207060705673849\
    9. 265774579830223671554026061117300483012903885770893074783710\
    10. 083450145620356667677191627276513995926532444279237315785832\
    11. 411595106453089134746365281031552217482363035280722591085079\
    12. 053410485925413958279617719034175332412908745680774313630190\
    13. 429314820559328748143552689295945058801322270313370955837837\
    14. 939182801848609300876356583948397645861551964542532682663945\
    15. 625356614462682551015176002433628234343684739800880514363921\
    16. 982340231989891351425389287014819359798014755509282450440511\
    17. 590838726938103384801541373585690893606978941566666714061214\
    18. 952341523168827712604946036245881214982452998386986623826275\
    19. 782780208928205527678781609589000725521486468983551558405472\
    20. 149903035076783644195574734088152324666290493119955560594634\
    21. 905391288186024902215444250421277955403412298227858394469856\
    22. 607272647132163832860126054679347881638761723785858733108109\
    23. 249157334220127702410373959720286708183036202841837581704881\
    24. 367895556630088230650972282944827258473951902831431040790814\
    25. 079538232104075905120989173307660289899942087873076421916033\
    26. 622143260549608274076012938515668898707915863945382394851328\
    27. 164677964192631597026176253407553188801750590935427267220117\
    28. 591817866992665840378311257621611574856498432538327068011953\
    29. 631534031790352912617015229051836886166704989498756486878095\
    30. 690013558017746707412183571476823027885971347137127534455141"
    31. Map = [[0] * 60 for i in range(30)]
    32. for i in range(30) :
    33. for j in range(60) :
    34. Map[i][j] = int(s[i*60+j])
    35. dp = [[0] * 60 for i in range(30)]
    36. for i in range(30) :
    37. for j in range(60) :
    38. if i == 0 and j == 0 : dp[i][j] = Map[0][0]
    39. elif j == 0 : dp[i][j] = dp[i-1][j] + Map[i][j]
    40. elif i == 0 : dp[i][j] = dp[i][j-1] + Map[i][j]
    41. else : dp[i][j] = max(dp[i-1][j],dp[i][j-1]) + Map[i][j]
    42. print(dp[29][59])

     

    c99375ab2a824860962e7836f029385f.png

    将小于2022的质数都找出来(质数筛),之后枚举质数列表的每一项prime,看2022-prime是否在列表中

    1. def find(num) :
    2. prime = []
    3. flag = [True] * (num+1)
    4. for i in range(2,num+1) :
    5. if flag[i] : prime.append(i)
    6. j = 0
    7. while prime[j] <= num // i :
    8. flag[prime[j] * i] = False
    9. if i % prime[j] == 0 : break
    10. j += 1
    11. return prime
    12. prime = find(2022)
    13. ans = 0
    14. for i in prime :
    15. if 2022 - i in prime : ans += 1
    16. print(ans >> 1)

     8fdf5fa34d0e4acebbf61dfcbe0eeb29.png

    签到题 略

    1. t,c,s = map(int,input().split())
    2. print(s*t//c - t)

     070a964d4a7c4a02a6e73b06982cac66.png

    开一个集合s,读入每一个单词,若该单词不在集合中,则输出并加入集合中。若在集合中则跳过。 

    1. N = int(input())
    2. s = set()
    3. for _ in range(N) :
    4. num = input()
    5. if num not in s :
    6. print(num)
    7. s.add(num)

     4f4db8c34b614c83a2691ba89af32794.png

    8a45aa68c3e94272813740054fdac42b.png

    将原字符串颠倒,看从第一个字符开始到第几个字符,以这两个字符为边界的字符串是回文串(至少为1,找最大长度) ,则剩下的字符(不属于回文串的,颠倒后+原字符串 就是答案,有点绕,看不懂可以私信我)

    1. s = input()
    2. leng = len(s)
    3. res = 0
    4. s = s[::-1]
    5. def check(s) :
    6. return s == s[::-1]
    7. if check(s) : res = leng
    8. else :
    9. for i in range(1,leng) :
    10. if check(s[:i]) : res = i
    11. t = leng - res
    12. s = s[::-1]
    13. tmp = s[:t]
    14. print(s + tmp[::-1])

      0ac9079d238646078b6cdbbc301fdfae.png

    6295b5c4923342baa36861dde8f6d73e.png

    枚举每一个不在边界上的点,看以它为中心,能贡献几个X图形,相加起来得到的和就是答案

    1. n,m = map(int,input().split())
    2. Map = []
    3. for i in range(n) : Map.append(list(input()))
    4. def bound(x,y) :
    5. return 0 <= x < n and 0 <= y < m
    6. def deep_check(t,a,b,c,d) :
    7. return t == a and t == b and t == c and t == d
    8. def check(x,y) :
    9. l = 0
    10. while 1 :
    11. l += 1
    12. ax = x + (-1) * l ; ay = y + (-1) * l
    13. bx = x + (-1) * l ; by = y + 1 * l
    14. cx = x + 1 * l ; cy = y + 1 * l
    15. dx = x + 1 * l ; dy = y + (-1) * l
    16. if bound(ax,ay) and bound(bx,by) and bound(cx,cy) and bound(dx,dy) : pass
    17. else : return l - 1
    18. if not deep_check(Map[x][y],Map[ax][ay],Map[bx][by],Map[cx][cy],Map[dx][dy]): return l - 1
    19. ans = 0
    20. for i in range(1,n-1) :
    21. for j in range(1,m-1) :
    22. ans += check(i,j)
    23. print(ans)

     ee0b92ed7a0b423085e4a0e028872fee.png

    归并排序求逆序对的模版题,只不过这里不是求逆序对的数量了,答案等于每一对逆序对中较大的那个数(即在左边的数)的和(仔细思考下为什么呢?🤔) 如果没有了解过归并排序,建议先学一下哈

    1. N = int(input())
    2. lst = list(map(int,input().split()))
    3. if N < 2 : print(0) ; exit()
    4. ans = 0
    5. def mergeSort(nums,l,r,tmp) :
    6. if l >= r : return
    7. mid = l + r >> 1
    8. mergeSort(nums,l,mid,tmp)
    9. mergeSort(nums,mid+1,r,tmp)
    10. merge(nums,l,mid,r,tmp)
    11. def merge(nums,l,mid,r,tmp) :
    12. global ans
    13. i, j = l, mid + 1
    14. while i <= mid and j <= r :
    15. if nums[i] <= nums[j] :
    16. tmp.append(nums[i])
    17. i += 1
    18. else :
    19. ans += nums[i]
    20. tmp.append(nums[j])
    21. j += 1
    22. while i <= mid : tmp.append(nums[i]) ; i += 1
    23. while j <= r : tmp.append(nums[j]) ; j += 1
    24. for k in range(len(tmp)) : nums[l+k] = tmp[k]
    25. tmp.clear()
    26. mergeSort(lst,0,N-1,[])
    27. print(ans)

    🔚 

     

     

     

     

     

     

     

     

     

     

     

  • 相关阅读:
    【01】区块链技术概述
    Linux 性能调优之硬件资源监控
    在 Windows 10 | Docker Desktop | Kubernetes 环境 使用 hostPath / local 为 POD 配置本机目录
    前端学习-BFC,作用和原理,typeof,parseIntString()函数,Boolean()函数,深浅克隆
    Windows远程桌面连线显示请稍后
    什么是Peppol ID?如何创建?
    MySQL列大小写敏感
    掌握深入挖掘数据本质的方法
    ROS2学习笔记:Launch脚本
    天池:数据分析达人赛1:用户情感可视化分析
  • 原文地址:https://blog.csdn.net/m0_54689021/article/details/128064065