蓝桥杯:刷题3.30

目录

1.七星填数      658

2.旋转第十届省赛

3. 迷宫与陷阱(第九届决赛)

 4.九宫幻方(第八届省赛)

 5.排列数

 6.门牌制作

 7.蛇形填数

 8.跑步锻炼

 9.既约分数


1.七星填数      658

from itertools import *
a=[1,2,3,4,5,7,8,9,10,12,13]
for x in permutations(a,11):
     x=list(x)
     if x[0]+x[1]+x[2]+x[3]==x[1]+x[4]+14+6==x[0]+x[4]+x[5]+x[6]==x[5]+x[7]+x[8]+14==x[6]+x[7]+x[9]+11==x[2]+x[10]+6+11==x[3]+x[10]+x[9]+x[8]:
          print(x)

2.旋转第十届省赛

n,m=map(int,input().split())
dp=[]
for i in range(n):
     s=list(map(int,input().split()))
     dp.append(s)
for i in range(m):
     for j in range(n-1,-1,-1):
          print(dp[j][i],end=' ')
     print()

3. 迷宫与陷阱(第九届决赛)

只得了40分,后面的超时啦

from queue import *
import sys
mp=[]
n,m=map(int,input().split())
for i in range(n):
     a=input()
     a=list(a)
     mp.append(a)
dir=[(0,1),(0,-1),(1,0),(-1,0)]
vis=[[0 for i in range(n)]for j in range(n)]
def bfs():
     q=Queue()
     q.put((0,0,0,0))
     while not q.empty():
          now=q.get()
          if now[0]==n-1 and now[1]==n-1:
               print(now[3])
               sys.exit()
          for i in range(4):
               new_x=now[0]+dir[i][0]
               new_y=now[1]+dir[i][1]
               if new_x<0 or new_y<0 or new_x>=n or new_y>=n:
                    continue
               if vis[new_x][new_y]==1 or mp[new_x][new_y]=='#':
                    continue
               if mp[new_x][new_y]=='%':
                    q.put((new_x,new_y,m,now[3]+1))
                    continue
               if mp[new_x][new_y]=='X':
                    if now[2]>0:
                         q.put((new_x,new_y,now[2]-1,now[3]+1))
                         continue
                    else:
                         continue
               if now[2]==0:
                    q.put((new_x,new_y,now[2],now[3]+1))
               else:
                    q.put((new_x,new_y,now[2]-1,now[3]+1))
bfs()   

 4.九宫幻方(第八届省赛)

s=["492357816","438951276","294753618","276951438","672159834","618753294","834159672","816357492"]
v=''
for i in range(3):
     a=list(map(str,input().split()))
     a=''.join(a)
     v+=a
p=[]
for j in range(8):
     if v[j]!='0':
          p.append(j)
q=[]
for i in range(7):
     for k in p:
          if v[k]!=s[i][k]:
               break
     else:
          q.append(s[i])
if len(q)>1:
     print(q)
else:
     kl=q[0]
     res=0
     for i in kl:
          print(i,end=' ')
          res+=1
          if res==3:
               res=0
               print()
          

 5.排列数

http://lx.lanqiao.cn/status.page

暴力解法,就只有10分,

from itertools import *
n,m=map(int,input().split())
ans=0
for x in permutations(range(1,n+1)):
     res=0
     for i in range(1,n-1):
          if (x[i]>x[i-1] and x[i]>x[i+1]) or (x[i]<x[i-1] and x[i]<x[i+1]):
               res+=1
     if res==m-1:
          ans+=1
print(ans%123456)

 6.门牌制作

res=0
for i in range(1,2021):
  while i>0:
    if i%10==2:
      res+=1
    i//=10
print(res)

 7.蛇形填数

sum=1
for i in range(1,20):
     sum+=i*4
print(sum)

 8.跑步锻炼

from datetime import *
start=date(2000,1,1)
end=date(2020,10,1)
day=timedelta(days=1)
res=0
while start<=end:
  if start.day==1 or start.weekday()==0:
    res+=2
  else:
    res+=1
  start+=day
print(res)

 9.既约分数

from math import *
res=0
for i in range(1,2021):
  for j in range(1,2021):
    if gcd(i,j)==1:
      res+=1
print(res)

10. 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值