题目恶心人,就没几道算法题,考了四五道模拟题,两道数学类型的题目,算法题就考了两三题,包括最后一题压轴题,难度太陡峭了吧
题目链接:蓝桥杯大赛历届真题 - Python 大学组 - 蓝桥云课 (lanqiao.cn)
目录
题目链接:蓝桥杯大赛历届真题 - Python 大学组 - 蓝桥云课 (lanqiao.cn)
1.门牌制作
答案:624
2.寻找2020
3.跑步锻炼
答案:8895
4.蛇形填数
答案:761
5.排序
6.成绩统计
7.单词分析
8.数字三角形
9.直线
10.装饰珠
1.门牌制作 答案:624
ans=0for i in range(1,2021): a=str(i) ans+=a.count('2')print(ans)
2.寻找2020
题目说考试的时候给了个文件,但是现在也找不到,就拿题目的案例来模拟了,考试的时候可能会因为题目的范围太大需要剪枝
martix=[]for i in range(6): martix.append(input())row=len(martix)col=len(martix[0])ans=0for i in range(row): for j in range(col-3): if martix[i][j:j+4]=="2020": ans+=1for j in range(col): for i in range(row-3): res="" for k in range(4): res+=martix[i+k][j] if res=="2020": ans+=1def isvalid(x,y): if x>=row or y>=col: return False else: return Truedx,dy=1,1for i in range(row): for j in range(col): res="" res+=martix[i][j] curx,cury=i,j for k in range(3): curx+=dx cury+=dy flag=False if isvalid(curx,cury): res+=martix[curx][cury] else: flag=True break if not flag: if res=="2020": ans+=1print(ans)
3.跑步锻炼 答案:8895
y1,m1,day1=2000,1,1y2,m2,day2=2020,10,1curday=6ans=0monthday=[0,31,28,31,30,31,30,31,31,30,31,30,31]while y1!=y2 or m1!=m2 or day1!=day2+1: if curday==1 or day1==1: ans+=2 else: ans+=1 curday=(curday+1)%7 day1+=1 flag=(y1%400==0) or (y1%4==0 and y1%100!=0) curmonthday=0 if m1!=2: curmonthday=monthday[m1] else: curmonthday=monthday[m1]+1 if day1>curmonthday: day1=1 m1+=1 if m1>12: m1=1 y1+=1print(ans)
4.蛇形填数
找规律
答案:761
ans=1n=int(input())for i in range(1,n): ans+=i*4print(ans)
5.排序 6.成绩统计
python输出百分号的方法
print("{:.2%}".format(x)
n=int(input())jige=0youxiu=0for i in range(n): x=int(input()) if x>=85: jige+=1 youxiu+=1 elif x>=60: jige+=1jige=jige/nyouxiu=youxiu/nprint("{:.0%}".format(jige))print("{:.0%}".format(youxiu))
7.单词分析
s=input()hashtable=[0 for i in range(26)]inttostring={-1:'c'}def change(x): num=ord(x)-ord('a') hashtable[num]+=1 inttostring[num]=xfor i in s: change(i)maxium=max(hashtable)maxindex=hashtable.index(maxium)print(inttostring[maxindex])print(maxium)
8.数字三角形
还可以剪枝
n=int(input())martix=[]dx=[1,1]dy=[0,1]def isvalid(row,col): if row>=n: return False if col>row: return False return Truedef dfs(row,col,left,right,sums): global maxium if row==n-1 and abs(left-right)<=1: maxium=max(maxium,sums) return for i in range(2): nextrow=row+dx[i] nextcol=col+dy[i] if isvalid(nextrow,nextcol): if i==0: # if abs(left+1-right)<=1: dfs(row+1,col,left+1,right,sums+martix[nextrow][nextcol]) elif i==1: # if abs(right+1-left)<=1: dfs(row+1,col+1,left,right+1,sums+martix[nextrow][nextcol])martix.append([int(input())])for i in range(n-1): martix.append(list(map(int,input().split())))maxium=-1dfs(0,0,0,0,martix[0][0])print(maxium)