【2020蓝桥杯】Python组真题解析 - 第十一届蓝桥杯
生活随笔
收集整理的這篇文章主要介紹了
【2020蓝桥杯】Python组真题解析 - 第十一届蓝桥杯
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本資料整理者&代碼編寫者:夏2同學
個人郵箱:1754082565@qq.com
請勿未經同意轉載 & 如有錯誤,歡迎指正
資料下載:https://download.csdn.net/download/xia_yanbing/16742326
備注:目前藍橋杯Python編輯器是:IDLE。
如果您想了解如何使用,可以參考這篇。
https://blog.csdn.net/xia_yanbing/article/details/114641646
目錄
- A-門牌制作.py
- 參考答案:624
- B-尋找2020.py
- 參考答案:16520
- C-跑步鍛煉.py
- 參考答案:8879
- D-蛇形填數.py
- 參考答案:761
- E-排序.py
- 參考答案:jonmlkihgfedcba
- F-成績統計.py
- G-單詞分析.py
- H-數字三角形.py
- I-平面分割.py
- J-裝飾珠.py
A-門牌制作.py
題目地址:https://www.lanqiao.cn/problems/592/learning/
參考答案:624
# https://www.lanqiao.cn/problems/592/learning/ # 參考答案:624total = 0 for i in range(1,2021):total += (str(i).count("2"))print(total)# 624B-尋找2020.py
題目地址:無在線練習題地址
參考答案:16520
# 無在線練習題地址 # 參考答案:16520def search_row(l):res = 0m = len(l[0])n = len(l)for i in range(n):for j in range(m-3):if l[i][j] == "2" and l[i][j+1] == "0" \and l[i][j+2] == "2" and l[i][j+3] == "0":res += 1return resdef search_xie(l):res = 0m = len(l[0])n = len(l)for i in range(n-3):for j in range(m-3):if l[i][j] == "2" and l[i+1][j+1] == "0" \and l[i+2][j+2] == "2" and l[i+3][j+3] == "0":res += 1return resdef search_col(l):res = 0m = len(l[0])n = len(l)for j in range(m):for i in range(n-3):if l[i][j] == "2" and l[i+1][j] == "0" \and l[i+2][j] == "2" and l[i+3][j] == "0":res += 1 return reswith open("2020.txt",'r') as fp:lines = fp.readlines()i = 0for line in lines:lines[i] = line.strip('\n')i+=1# 16520print(search_row(lines)+search_xie(lines)+search_col(lines))C-跑步鍛煉.py
題目地址:https://www.lanqiao.cn/problems/597/learning/
參考答案:8879
# https://www.lanqiao.cn/problems/597/learning/ # 參考答案:8879flag = 6def nextDay(date):'''date: 格式 yyyy-mm-ddreturn next_date,is_monday,is_month_begin星期一和月初'''date = list(map(int,date.split("-")))y,m,d = dated+=1if m == 12 and d == 32:y += 1m = 1d = 1elif m == 2:if is_leap_year(y):if d == 30:m = 3d = 1else:if d == 29:m = 3d = 1elif is_big_month(m):if d == 32:m += 1d = 1elif not is_big_month(m):if d == 31:m += 1d = 1global flagadd_week()is_month_begin = True if d == 1 else Falseis_monday = True if flag == 1 else Falsenew_date = "%d-%02d-%02d" % (y,m,d)return new_date,is_monday,is_month_begindef is_leap_year(year):if year % 4 == 0 and year % 100 != 0:return Trueelif year % 400 == 0:return Truereturn Falsedef is_big_month(month):if month in [1,3,5,7,8,10,12]:return Trueelse:return Falsedef add_week():global flagflag = (flag + 1) % 8 if (flag + 1) % 8 else 1def main():start_time = "2000-01-01"# end_time = "2000-01-10"end_time = "2020-10-01"total = 2while start_time != end_time:start_time,is_monday,is_month_begin = nextDay(start_time)if is_monday or is_month_begin:total += 2else:total += 1print(start_time,is_monday,is_month_begin,total)print(total)# ans = main()D-蛇形填數.py
題目地址:https://www.lanqiao.cn/problems/594/learning/
參考答案:761
# https://www.lanqiao.cn/problems/594/learning/ # 參考答案:761def print_out(lst):# 一行行輸出for line in lst:for x in line:print("%04d" % x,end=" ")# print(" ".join(map(str, i)))print()lst = [i for i in range(1000)]num = 1res = [[0 for i in range(101)] for i in range(101)]i, j = 0, 0# res[0][0] = num while i != 100 and j != 100:num += 1# 向右j += 1res[i][j] = numwhile j > 0:# 向斜左下角num += 1i += 1j -= 1res[i][j] = numnum += 1# 向下i += 1res[i][j] = numwhile i > 0:# 向斜右上角num += 1i -= 1j += 1res[i][j] = num# 蛇形填數字 with open ('./out.txt','w+') as fp:for line in res:for x in line:fp.write("%04d " % x)fp.write("\n")```E-排序.py
題目地址:https://www.lanqiao.cn/problems/598/learning/
參考答案:jonmlkihgfedcba
# https://www.lanqiao.cn/problems/598/learning/ # 參考答案:jonmlkihgfedcbaimport randomcount = 0# def bubble_sort(lst): # n = len(lst) # for i in range(n-1): # # is_ordered = True # j = 0 # while j < n-i-1: # if lst[j] > lst[j+1]: # # 交換 # lst[j], lst[j+1] = lst[j+1], lst[j] # global count # count += 1 # # is_ordered = False # j += 1def bubble_sort(lst):n = len(lst)for i in range(n-1):is_ordered = Truej = 0while j < n-i-1:if lst[j] > lst[j+1]:# 交換lst[j], lst[j+1] = lst[j+1], lst[j]global countcount += 1is_ordered = Falsej += 1if is_ordered:# 結束冒泡break# string =[chr(i) for i in range(ord('a'),ord('p'))]# data = ['o', 'n', 'm', 'l', 'k', 'j', # 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a']# 1. 最短 2. 字典序低data = ['j', 'o', 'n', 'm', 'l', 'k','i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a']# data = string[::-1]print(data) bubble_sort(data) print(data) print(count)F-成績統計.py
題目地址:https://www.lanqiao.cn/problems/502/learning
# https://www.lanqiao.cn/problems/502/learningfrom decimal import *n = int(input())socres = [int(input()) for i in range(n)]youxiu = 0 jige = 0for i in socres:if i >= 85:youxiu += 1if i >= 60:jige += 1# 高精度 percent1 = int(round(float(Decimal(jige) / Decimal(n)) * 100, 0)) percent2 = int(round(float(Decimal(youxiu) / Decimal(n)) * 100, 0))print("%d%%" % percent1) print("%d%%" % percent2)G-單詞分析.py
題目地址:https://www.lanqiao.cn/problems/504/learning
# https://www.lanqiao.cn/problems/504/learning# 記錄26個英文字母的順序 charLst = [0] * 26string = input()for char in string:charLst[ord(char)-97] += 1max_value = max(charLst) res_index = charLst.index(max_value) res_chr = chr(res_index + 97)print(res_chr) print(max_value)H-數字三角形.py
題目地址:https://www.lanqiao.cn/problems/505/learning/
# https://www.lanqiao.cn/problems/505/learning/# 借鑒了 https://www.jianshu.com/p/c20b6b9a178a (C++)if __name__ == '__main__':# MAX = 105n = int(input())MAX = n+2nums = [[0 for i in range(1, MAX)] for i in range(1, MAX)]dp = [[0 for i in range(1, MAX)] for i in range(1, MAX)]# 讀取用戶輸入for i in range(1, n+1):line = map(int, input().split(" "))for j, e in enumerate(line):nums[i][j+1] = e# print(nums)# 初始化最后一行if n % 2 == 0:dp[n][n//2] = nums[n][n//2]dp[n][n//2 + 1] = nums[n][n//2 + 1]else:dp[n][n//2 + 1] = nums[n][n//2 + 1]# 從后往前依次遍歷for i in range(n-1, 0, -1):for j in range(1, i+1):# 如果下一行左邊或者右邊不為0if dp[i+1][j] != 0 or dp[i+1][j+1] != 0:dp[i][j] = nums[i][j] + max(dp[i+1][j], dp[i+1][j+1])print(dp[1][1])I-平面分割.py
題目地址:https://www.lanqiao.cn/problems/503/learning/
# https://www.lanqiao.cn/problems/503/learning/# 思路:畫幾張圖觀察一下可以發現一下特點: # 1、重邊不會影響區域數目。 # 2、每新加入一條邊只要不是重邊區域數目必定+1。 # 3、加入的新邊如果與之前加入的邊每有一個交點則區域數目+1。n = int(input())# 存放直線數(必須得不重合) set_line = set() # 存放交點數 set_point = set()for i in range(n):tmp = tuple(input().split())set_line.add(tmp)set_point.add(tmp[0])print(len(set_line)+len(set_point))J-裝飾珠.py
題目地址:https://www.lanqiao.cn/problems/507/learning/
# https://www.lanqiao.cn/problems/507/learning/import os import syss = [] r = [] m = []for i in range(6):s.append(list(map(int, input().split()))) n = int(input()) for i in range(n):r.append(list(map(int, input().split()))) for i in range(6):p = s[i]for j in range(n):if i == 0:m.append(p[1:].count(int(j+1)))else:m[j] += p[1:].count(int(j+1))'''print(m)''' '''用m[j]記錄6件裝備共有 j+1級孔m[j]個''' mm = m '''假設j級孔全用j級珠子''' up = [] down = [] '''up記錄加一顆珠子提升的價值,down記錄少一顆珠子減少的價值'''def up1(k):if mm[k] >= r[k][1]:return 0elif mm[k] == 0:return r[k][2]else:return r[k][2+mm[k]]-r[k][1+mm[k]]def down1(k):if mm[k] == 1:return r[k][2]elif mm[k] > r[k][1]:return 0else:return r[k][1+mm[k]]-r[k][mm[k]]for i in range(n):up.append(up1(i))down.append(down1(i))'''print(up,down)''' '''第n+1級孔,如果1到n級孔中珠子加1的價值比它減少1顆的價值大,則數值各加1、減1,up、down更新'''def main1(n):if n == 0:returnwhile max(up[:n]) > down[n] and mm[n] > 0:t = up.index(max(up[:n]))mm[t] += 1up[t] = up1(t)mm[n] -= 1down[n] = down1(n)main1(n-1)returnpoint = 0 main1(n-1) '''輸入有n級,為了和形參統一,此處減1''' '''print(up,down) print(mm)''' for i in range(n):if mm[i] != 0:point += r[i][1+mm[i]] print(point) '''得到總價值'''總結
以上是生活随笔為你收集整理的【2020蓝桥杯】Python组真题解析 - 第十一届蓝桥杯的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Windows下cmd常用命令【5分钟掌
- 下一篇: 2018 年年终总结 -- 斜杠前进