2021第十二届蓝桥杯Python组国赛 (真题&题解)

十二届蓝桥杯国赛试题及解析(python组)

  1. A题:带宽
  2. B题:纯质数
  3. C题:完全日期
  4. D题:最小权值
  5. E题:大写
  6. F题:123
  7. G题:冰山
  8. H题:和与乘积
  9. I题:二进制问题
  10. 10.J题:翻转括号序列

先分享试题,再逐步完善题解
试题源文件链接在文末
我的感悟:


A题:带宽

2021第十二届蓝桥杯Python组国赛 (真题&题解)_第1张图片
【分析】

【代码】

#结果为 25
1Byte=8bit
1MB/s=8Mbps=8Mb/s
200*1024/8=25600KB/s=25MB/s

B题:纯质数

2021第十二届蓝桥杯Python组国赛 (真题&题解)_第2张图片

【分析】

【代码】

#纯质数
from math import *

#判断是否为质数
def isPrime(n):
    m=int(sqrt(n))+1
    for i in range(2,m):
        if n%i==0:
            return False
    return True

#判断每一位是否都为质数
def eve(n):
    res=['2','3','5','7']
    s=str(n)
    if s.count(res[0])+s.count(res[1])+s.count(res[2])+s.count(res[3])==len(s):
        return 1
    return 0

ans=0
for i in range(20210606):
    if (isPrime(i) and eve(i)):
        ans+=1
print(ans)
    
    


C题:完全日期

2021第十二届蓝桥杯Python组国赛 (真题&题解)_第3张图片

【分析】

【代码】

from datetime import *
from math import *
a=date(2001,1,1)
b=date(2021,12,31)
gap=timedelta(days=1)
#求每个数位的和
def cul(n):
    summ=0
    nn=str(n)
    for i in nn:
        summ+=int(i)
    return summ
#判断是否为完全平方数
def judge(mm):
    x=sqrt(mm)
    y=int(sqrt(mm))
    if x==y:
        return 1
    return 0

ans=0
while a!=b:
    a=a+gap
    year=a.year
    month=a.month
    day=a.day
    #和
    summm=cul(year)+cul(month)+cul(day)
    #print(a)
    #print(summm)
    if judge(summm):
        ans+=1
        print(a)
print(ans)

        
    
    


D题:最小权值

2021第十二届蓝桥杯Python组国赛 (真题&题解)_第4张图片

【分析】

【代码】



E题:大写

2021第十二届蓝桥杯Python组国赛 (真题&题解)_第5张图片

【分析】

【代码】



F题:123

2021第十二届蓝桥杯Python组国赛 (真题&题解)_第6张图片

【分析】

【代码】



G题:冰山

2021第十二届蓝桥杯Python组国赛 (真题&题解)_第7张图片
【分析】

【代码】



H题:和与乘积

2021第十二届蓝桥杯Python组国赛 (真题&题解)_第8张图片

【分析】

【代码】

#样例不能完全通过
n=int(input())
res=list(map(int,input().split()))
ans=0
def judge(n):
    summ=sum(n)
    cul=1
    for i in ress:
        cul*=i
    if summ==cul:
        return 1
    return 0

for i in range(n):
    for j in range(i,n+1):
        ress=res[i:j]
        if len(ress)>0:
            if judge(ress):
                ans+=1
        j+=1
    i+=1
print(ans)


I题:二进制问题

2021第十二届蓝桥杯Python组国赛 (真题&题解)_第9张图片

【分析】

【代码】

#样例不能完全通过
N,K=map(int,input().split())
ans=0
for i in range(1,N+1):
    s=bin(i)[2:]
    
    if s.count("1")==K:
        ans+=1
print(ans)

J题:翻转括号序列

2021第十二届蓝桥杯Python组国赛 (真题&题解)_第10张图片
2021第十二届蓝桥杯Python组国赛 (真题&题解)_第11张图片

【分析】

【代码】



链接:https://pan.baidu.com/s/1KoCDQ34GBkf_l3y6t768ww
提取码:7e0n

你可能感兴趣的:(算法,算法,python,经验分享,程序人生,其他)