当前位置:   article > 正文

第十五届蓝桥杯模拟赛第一期(Python版)_十五届蓝桥杯python真题

十五届蓝桥杯python真题

本文记录一下本人的解题。

前提说明:本人没有学过任何算法,解题仅供参考!

大多数情况下,俺的暴力还是能过一部分数据的,但是数据太大的时候就过不了了,我也没有办法,只能参考某些大佬的优化了。

1、第一题

  1. print(int("AAA",16))
  2. # 答案是2730

 2、第二题

这个题目可以直接手算,也可以打开Excel,直接查。我个人选择的后者,答案是:BYT。

3、第三题

  1. import datetime
  2. dat1 = datetime.date(1900,1,1)
  3. dat2 = datetime.date(9999,12,31)
  4. comaaa = 0
  5. def com(yl,year,ml,month,dl,day):
  6. s,y = 0,0
  7. for i in range(yl):
  8. s = s +int(year[i])
  9. for u in range(ml):
  10. y = y + int(month[u])
  11. for x in range(dl):
  12. y = y+ int(day[x])
  13. if s == y:
  14. return True
  15. while dat1 != dat2:
  16. yl,year,ml,month,dl,day = len(str(dat1.year)),str(dat1.year),len(str(dat1.month)),str(dat1.month),len(str(dat1.day)),str(dat1.day)
  17. if com(yl,year,ml,month,dl,day):
  18. comaaa = comaaa+1
  19. dat1 = dat1 + datetime.timedelta(1)
  20. print(comaaa)

暴力直接冲烂它,结果是:70910。

4、第四题

  1. list = [99,22,51,63,72,61,20,88,40,21,63,30,11,18,99,12,93,16,7,53,64,9,28,84,34,96,52,82,51,77]
  2. cons = 0
  3. for i in range(len(list)):
  4. for u in range(i+1, len(list)):
  5. if list[i]*list[u] >= 2022:
  6. cons += 1
  7. print(cons)

 答案是:189。

5、第五题

 

 

  1. 110010000011111110101001001001101010111011011011101001111110
  2. 010000000001010001101100000010010110001111100010101100011110
  3. 001011101000100011111111111010000010010101010111001000010100
  4. 101100001101011101101011011001000110111111010000000110110000
  5. 010101100100010000111000100111100110001110111101010011001011
  6. 010011011010011110111101111001001001010111110001101000100011
  7. 101001011000110100001101011000000110110110100100110111101011
  8. 101111000000101000111001100010110000100110001001000101011001
  9. 001110111010001011110000001111100001010101001110011010101110
  10. 001010101000110001011111001010111111100110000011011111101010
  11. 011111100011001110100101001011110011000101011000100111001011
  12. 011010001101011110011011111010111110010100101000110111010110
  13. 001110000111100100101110001011101010001100010111110111011011
  14. 111100001000001100010110101100111001001111100100110000001101
  15. 001110010000000111011110000011000010101000111000000110101101
  16. 100100011101011111001101001010011111110010111101000010000111
  17. 110010100110101100001101111101010011000110101100000110001010
  18. 110101101100001110000100010001001010100010110100100001000011
  19. 100100000100001101010101001101000101101000000101111110001010
  20. 101101011010101000111110110000110100000010011111111100110010
  21. 101111000100000100011000010001011111001010010001010110001010
  22. 001010001110101010000100010011101001010101101101010111100101
  23. 001111110000101100010111111100000100101010000001011101100001
  24. 101011110010000010010110000100001010011111100011011000110010
  25. 011110010100011101100101111101000001011100001011010001110011
  26. 000101000101000010010010110111000010101111001101100110011100
  27. 100011100110011111000110011001111100001110110111001001000111
  28. 111011000110001000110111011001011110010010010110101000011111
  29. 011110011110110110011011001011010000100100101010110000010011
  30. 010011110011100101010101111010001001001111101111101110011101
  1. data =[
  2. "110010000011111110101001001001101010111011011011101001111110",
  3. "010000000001010001101100000010010110001111100010101100011110",
  4. "001011101000100011111111111010000010010101010111001000010100",
  5. "101100001101011101101011011001000110111111010000000110110000",
  6. "010101100100010000111000100111100110001110111101010011001011",
  7. "010011011010011110111101111001001001010111110001101000100011",
  8. "101001011000110100001101011000000110110110100100110111101011",
  9. "101111000000101000111001100010110000100110001001000101011001",
  10. "001110111010001011110000001111100001010101001110011010101110",
  11. "001010101000110001011111001010111111100110000011011111101010",
  12. "011111100011001110100101001011110011000101011000100111001011",
  13. "011010001101011110011011111010111110010100101000110111010110",
  14. "001110000111100100101110001011101010001100010111110111011011",
  15. "111100001000001100010110101100111001001111100100110000001101",
  16. "001110010000000111011110000011000010101000111000000110101101",
  17. "100100011101011111001101001010011111110010111101000010000111",
  18. "110010100110101100001101111101010011000110101100000110001010",
  19. "110101101100001110000100010001001010100010110100100001000011",
  20. "100100000100001101010101001101000101101000000101111110001010",
  21. "101101011010101000111110110000110100000010011111111100110010",
  22. "101111000100000100011000010001011111001010010001010110001010",
  23. "001010001110101010000100010011101001010101101101010111100101",
  24. "001111110000101100010111111100000100101010000001011101100001",
  25. "101011110010000010010110000100001010011111100011011000110010",
  26. "011110010100011101100101111101000001011100001011010001110011",
  27. "000101000101000010010010110111000010101111001101100110011100",
  28. "100011100110011111000110011001111100001110110111001001000111",
  29. "111011000110001000110111011001011110010010010110101000011111",
  30. "011110011110110110011011001011010000100100101010110000010011",
  31. "010011110011100101010101111010001001001111101111101110011101"]
  32. def dfs(x, y, num):
  33. vis[x][y] = 1
  34. for dx,dy in [(1, 0), (-1, 0), (0,1), (0, -1)]:
  35. current_x = x + dx
  36. current_y = y + dy
  37. if 0 <= current_x < 30 and 0 <= current_y <60:
  38. try:
  39. if vis[current_x][current_y] != 1 and data[current_x][current_y] == '1':
  40. num = dfs(current_x,current_y,num)
  41. except:
  42. print(current_x)
  43. print(current_y)
  44. return num + 1
  45. res = 0
  46. vis = [[0 for i in range(60)] for j in range(30)]
  47. for i in range(30):
  48. for j in range(60):
  49. if data[i][j] == '1' and vis[i][j] == 0:
  50. num = 0
  51. num = dfs(i,j,num)
  52. res = max(num, res)
  53. print(res)

答案是:148。

6、第六题

  1. n = eval(input())
  2. nm = eval(input())
  3. nm = nm % 7
  4. if n + nm >7:
  5. print((n + nm) % 7)
  6. else:
  7. print(n + nm)

7、第七题 

 

 

  1. w, h, n, r = map(int, input().split())
  2. points = set()
  3. ans = 0
  4. for _ in range(n):
  5. a, b = map(int, input().split())
  6. points.add((a, b))
  7. def check(x, y):
  8. for a, b in points:
  9. if pow(x - a, 2) + pow(y - b, 2) <= r * r:
  10. return True
  11. return False
  12. for i in range(w + 1):
  13. for j in range(h + 1):
  14. if check(i, j):
  15. ans += 1
  16. print(ans)

 8、第八题

 

  1. ponit = set()
  2. s = set()
  3. n,m = map(int,input().split())
  4. for b in range(n):
  5. for v in range(m):
  6. s.add((b,v))
  7. t = eval(input())
  8. for i in range(t):
  9. r1,c1,r2,c2 = map(int,input().split())
  10. for u in range(r1-1,r2):
  11. for x in range(c1-1,c2):
  12. ponit.add((u,x))
  13. ponit = set(ponit)
  14. result = s - ponit
  15. print(len(result))

 9、第九题

 

  1. # 错误的暴力做法,直接寄了
  2. # 定义上、下、左、右
  3. dir = [(-1, 0), (1, 0), (0, -1), (0, 1)]
  4. # 是否在场地中
  5. def is_in_mat(mat, row, col):
  6. if 0 <= row < len(mat) and 0 <= col < len(mat[0]):
  7. return True
  8. # DFS
  9. def dfs(mat, row, col, visited):
  10. height = mat[row][col]
  11. max_distance = 1
  12. for d in dir:
  13. new_row = row + d[0]
  14. new_col = col + d[1]
  15. if is_in_mat(mat, new_row, new_col) and not visited[new_row][new_col] and mat[new_row][new_col] < height:
  16. visited[new_row][new_col] = True
  17. distance = dfs(mat, new_row, new_col, visited)
  18. max_distance = max(max_distance, distance)
  19. return max_distance + 1
  20. # 读取输入
  21. n, m = map(int, input().split())
  22. mat = [list(map(int, input().split())) for _ in range(n)]
  23. # 遍历初始化
  24. result = 0
  25. list_maxdis = []
  26. for i in range(n):
  27. for j in range(m):
  28. visited = [[False] * m for _ in range(n)]
  29. visited[i][j] = True
  30. distance = dfs(mat, i, j, visited)
  31. u = max(result, distance)
  32. list_maxdis.append(u)
  33. # 输出结果
  34. print(max(list_maxdis))
  1. # 记忆优化做法,这个能过
  2. n, m = map(int, input().split())
  3. lst = [list(map(int, input().split())) for _ in range(n)]
  4. cache = [[-1] * m for _ in range(n)]
  5. def dfs(x, y):
  6. if cache[x][y] != -1:
  7. return cache[x][y]
  8. ans = 1
  9. for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
  10. xx = dx + x
  11. yy = dy + y
  12. if 0 <= xx < n and 0 <= yy < m and lst[xx][yy] < lst[x][y]:
  13. ans = max(dfs(xx, yy) + 1, ans)
  14. cache[x][y] = ans
  15. return ans
  16. res = 0
  17. for i in range(n):
  18. for j in range(m):
  19. res = max(dfs(i, j), res)
  20. print(res)

10、第十题 

  1. # 又是暴力做的,有两个数据过不去
  2. n = int(input())
  3. a = list(map(int, input().split()))
  4. k = int(input())
  5. result = []
  6. for i in range(n):
  7. left = max(0, i - k)
  8. right = min(n - 1, i + k)
  9. min_value = min(a[left:right+1])
  10. result.append(min_value)
  11. print(' '.join(map(str, result)))
  1. # 自行dp吧,看到有大佬过了
  2. n = int(input())
  3. a = list(map(int, input().split()))
  4. t = int(input())
  5. dp = [0] * n
  6. dp[0] = min(a[1 - t if 1 - t >= 0 else 0: 1 + t + 1])
  7. for i in range(1, n):
  8. p1 = i - t - 1 if i - t - 1 >= 0 else 0 # 左指针-1
  9. p2 = i + t if i + t < n else n - 1
  10. if a[p1] == dp[i - 1]: # 出区间了,重新计算
  11. dp[i] = min(a[p1 + 1: p2])
  12. else:
  13. dp[i] = dp[i - 1] if a[p2] > dp[i - 1] else a[p2]
  14. print(' '.join([str(x) for x in dp]))

 11、第十一题

 有64个六位数字,每个数各个位上的数字之和最大的是哪个?(填空题,有重复的找第一个)

nums = [454771, 329157, 801601, 580793, 755604, 931703, 529875, 361797,
        604358, 529564, 574776, 821517, 195563, 688516, 223321, 607845,
        284772, 603562, 543328, 707484, 533688, 380468, 233733, 257995,
        896582, 670074, 912386, 702393, 722092, 834842, 126346, 606526,
        376981, 910643, 413754, 945725, 817853, 651778, 350775, 676550,
        316935, 487808, 939526, 900568, 423326, 298936, 927671, 539773,
        136326, 717022, 886675, 466684, 436470, 558644, 267231, 902422,
        743580, 857864, 529622, 320921, 595409, 486860, 951114, 558787]
  1. nums = [454771, 329157, 801601, 580793, 755604, 931703, 529875, 361797,
  2. 604358, 529564, 574776, 821517, 195563, 688516, 223321, 607845,
  3. 284772, 603562, 543328, 707484, 533688, 380468, 233733, 257995,
  4. 896582, 670074, 912386, 702393, 722092, 834842, 126346, 606526,
  5. 376981, 910643, 413754, 945725, 817853, 651778, 350775, 676550,
  6. 316935, 487808, 939526, 900568, 423326, 298936, 927671, 539773,
  7. 136326, 717022, 886675, 466684, 436470, 558644, 267231, 902422,
  8. 743580, 857864, 529622, 320921, 595409, 486860, 951114, 558787]
  9. uhhh = []
  10. def uh(i):
  11. a1 = str(i)[0]
  12. a2 = str(i)[1]
  13. a3 = str(i)[2]
  14. a4 = str(i)[3]
  15. a5 = str(i)[4]
  16. a6 = str(i)[5]
  17. s = int(a1)+int(a2)+int(a3)+int(a4)+int(a5)+int(a6)
  18. return s
  19. for u in nums:
  20. uhhh.append(uh(u))
  21. print(nums[uhhh.index(min(uhhh))])

 答案是:223321。

12、第十二题

  1. L = int(input())
  2. count = 0
  3. while L > 1:
  4. L //= 2
  5. count += 1
  6. print(count+1)

 13、第十三题

  1. def delete_characters(string, n,m):
  2. if string is None or n == 0 or m <= 0:
  3. return string
  4. if m >= n:
  5. return ""
  6. stack = []
  7. for c in string:
  8. while stack and c < stack[-1] and m > 0:
  9. stack.pop()
  10. m -= 1
  11. stack.append(c)
  12. while m > 0 and stack:
  13. stack.pop()
  14. m -= 1
  15. result = ""
  16. while stack:
  17. result = stack.pop() + result
  18. return result
  19. n,m = map(int,input().split())
  20. S = input()
  21. result = delete_characters(S, n,m)
  22. print(result)

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/504306
推荐阅读
相关标签
  

闽ICP备14008679号