第十四届蓝桥杯模拟赛(Python)

写在前面

  1. 本篇题解涵盖范围为1 - 8 题,最后两题本人没能解出来
  2. 使用语言为Python
  3. 过样例 不确定能否AC
  4. 仅供参考 若有错误 欢迎指出
  5. 最后两题若有佬会 可以评论给出你的思路 感激不尽

 第十四届蓝桥杯模拟赛(Python)_第1张图片

 

# 直接调用转二进制函数即可
# 具体用法请查官方文档

s = 2022
ans = bin(s)
print(len(ans[2:]))

 

 第十四届蓝桥杯模拟赛(Python)_第2张图片

调用datetime函数,枚举每一天并判断是否符合要求 

import datetime

start = datetime.date(2022,1,1)
ans = 0 
diff = datetime.timedelta(1)
end = datetime.date(2022,12,31)

def check(date) :
    
    if datetime.date.weekday(date) == 5 or datetime.date.weekday(date) == 6 :
        return True
    date = str(date)
    if date[-2:] == '01' or date[-2:] == '11' or date[-2:] == '21' or date[-2:] == '31' :
        return True
    return False

while start <= end :
    if check(start) : ans += 1
    start += diff
    
print(ans)

 

 第十四届蓝桥杯模拟赛(Python)_第3张图片

简单模拟,大于12时输出答案 


idx = 1 
target = 12 
tot = 0 
ans = 0

while tot < target :
    tot += 1 / idx 
    ans += 1 
    idx += 1
    
print(ans)

 

第十四届蓝桥杯模拟赛(Python)_第4张图片 

 遍历每个点,判断是否为山谷即可


s = "PHQGHUMEAYLNLFDXFIRCVSCXGGBWKFNQDUXWFNFOZVSRTKJPREPGGXRPNRVY\
STMWCYSYYCQPEVIKEFFMZNIMKKASVWSRENZKYCXFXTLSGYPSFADPOOEFXZBC\
OEJUVPVABOYGPOEYLFPBNPLJVRVIPYAMYEHWQNQRQPMXUJJLOOVAOWUXWHMS\
NCBXCOKSFZKVATXDKNLYJYHFIXJSWNKKUFNUXXZRZBMNMGQOOKETLYHNKOAU\
GZQRCDDIUTEIOJWAYYZPVSCMPSAJLFVGUBFAAOVLZYLNTRKDCPWSRTESJWHD\
IZCOBZCNFWLQIJTVDWVXHRCBLDVGYLWGBUSBMBORXTLHCSMPXOHGMGNKEUFD\
XOTOGBG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IHOSWKIFYGTYDHACWYHSGEWZMTGONZLTJHGAUHNIHREQGJFWKJS\
MTPJHAEFQZAAULDRCHJCCDYRFVVRIVUYEEGFIVDRCYGURQDREDAKUBNFGUPR\
OQYLOBCWQXKZMAUSJGMHCMHGDNMPHNQKAMHURKTRFFACLVGRZKKLDACLLTEO\
JOMONXRQYJZGINRNNZWACXXAEDRWUDXZRFUSEWJTBOXVYNFHKSTCENAUMNDD\
XFDMVZCAUTDCCKXAAYDZSXTTOBBGQNGVVPJGOJOGLMKXGBFCPYPCKQCHBDDZ\
WRXBZMQRLXVOBTWHXGINFGFRCCLMZNMJUGWWBSQFCIHUBSJOLLMSQSGHMCPH\
ELSOTFLBGSFNPCUZSRUPCHYNVZHCPQUGRIWNIQXDFJPWPXFBLKPNPEELFJMT"
    
Map = [[0] * 60 for i in range(30)]

for i in range(30) :
    for j in range(60) :
        Map[i][j] = s[i*30+j]
    
def check(x,y) :
    
    for i,j in [(1,0),(0,1),(0,-1),(-1,0)] :
        px = x + i ; py = y + j
        if ord(Map[x][y]) >= ord(Map[px][py]) : return False
    
    return True
# for i in range(3) :
#     for j in range(5) :
#         print(Map[i][j],end=' ')
#     print()
ans = 0 
    
for i in range(30) :
    for j in range(60) :
        if i == 0 or j == 0 or i == 29 or j == 59 : continue
        if check(i,j) : ans += 1
        
print(ans)

 

第十四届蓝桥杯模拟赛(Python)_第5张图片 

 二位前缀和,枚举起点和终点的横坐标和列坐标即可


Map = [[0] * 101 for i in range(101)]

Map[1][1] = 1 
for i in range(1,101) :
    for j in range(1,101) :
        if i == 1 and j == 1 : continue
        if j == 1 : Map[i][j] = Map[i-1][j] + 1 
        else : Map[i][j] = Map[i][j-1] + 2 
        
for i in range(1,101) :
    for j in range(1,101) :
        Map[i][j] += Map[i-1][j] + Map[i][j-1] - Map[i-1][j-1] 
        
print(Map[3][3])
        
ans = float('inf')

for i in range(1,101) :
    for j in range(i,101) :
        for k in range(1,101) :
            for t in range(k,101) :
                if Map[j][t] - Map[j][k-1] - Map[i-1][t] + Map[i-1][k-1] == 2022 :
                    ans = min(ans,(j-i+1)*(t-k+1))
                    
print(ans)

 

 第十四届蓝桥杯模拟赛(Python)_第6张图片

模拟 , 签到题


s = int(input())
t = int(input())

ans = 0 
if t > s : print(t - s)
else : print(t + 7 - s)

 

 第十四届蓝桥杯模拟赛(Python)_第7张图片

直接调用replace函数 


s = input()
s = s.replace('a', 'A')
s = s.replace('e', 'E')
s = s.replace('i', 'I')
s = s.replace('o', 'O')
s = s.replace('u', 'U')

print(s)

 第十四届蓝桥杯模拟赛(Python)_第8张图片第十四届蓝桥杯模拟赛(Python)_第9张图片

按照输入的顺序,当前的时间-上一个时间✖️电流✖️电压,计算总和 

n = int(input())
ans = 0

for i in range(n) :
    s,U,I = input().split()
    H,M,S = s.split(':')
    if i == 0 :
        oldU = int(U) ; oldI = int(I)
        oldH = int(H) ; oldM = int(M) ; oldS = int(S)
    else :
        ans += ((int(H) - oldH) * 3600 + (int(M) - oldM) * 60 + (int(S) - oldS)) * oldU * oldI
        oldU = int(U) ; oldI = int(I)
        oldH = int(H) ; oldM = int(M) ; oldS = int(S)
        
print(ans)
        
        

 


 第十四届蓝桥杯模拟赛(Python)_第10张图片

 

 

第十四届蓝桥杯模拟赛(Python)_第11张图片 

 第十四届蓝桥杯模拟赛(Python)_第12张图片

# 没有思路 


 

 

第十四届蓝桥杯模拟赛(Python)_第13张图片 

 

 第十四届蓝桥杯模拟赛(Python)_第14张图片

# 没有思路 

 

 

 

你可能感兴趣的:(蓝桥杯,蓝桥杯)