蓝桥题库个别题解
python解法
递增序列
划重点:左下到右上排列,从左往右和从上往下是不同顺序(也就是算两种)
mat=['VLPWJVVNNZSWFGHSFRBCOIJTPYNEURPIGKQGPSXUGNELGRVZAG',
'SDLLOVGRTWEYZKKXNKIRWGZWXWRHKXFASATDWZAPZRNHTNNGQF',
'ZGUGXVQDQAEAHOQEADMWWXFBXECKAVIGPTKTTQFWSWPKRPSMGA',
'BDGMGYHAOPPRRHKYZCMFZEDELCALTBSWNTAODXYVHQNDASUFRL',
'YVYWQZUTEPFSFXLTZBMBQETXGXFUEBHGMJKBPNIHMYOELYZIKH',
'ZYZHSLTCGNANNXTUJGBYKUOJMGOGRDPKEUGVHNZJZHDUNRERBU',
'XFPTZKTPVQPJEMBHNTUBSMIYEGXNWQSBZMHMDRZZMJPZQTCWLR',
'ZNXOKBITTPSHEXWHZXFLWEMPZTBVNKNYSHCIQRIKQHFRAYWOPG',
'MHJKFYYBQSDPOVJICWWGGCOZSBGLSOXOFDAADZYEOBKDDTMQPA',
'VIDPIGELBYMEVQLASLQRUKMXSEWGHRSFVXOMHSJWWXHIBCGVIF',
'GWRFRFLHAMYWYZOIQODBIHHRIIMWJWJGYPFAHZZWJKRGOISUJC',
'EKQKKPNEYCBWOQHTYFHHQZRLFNDOVXTWASSQWXKBIVTKTUIASK',
'PEKNJFIVBKOZUEPPHIWLUBFUDWPIDRJKAZVJKPBRHCRMGNMFWW',
'CGZAXHXPDELTACGUWBXWNNZNDQYYCIQRJCULIEBQBLLMJEUSZP',
'RWHHQMBIJWTQPUFNAESPZHAQARNIDUCRYQAZMNVRVZUJOZUDGS',
'PFGAYBDEECHUXFUZIKAXYDFWJNSAOPJYWUIEJSCORRBVQHCHMR',
'JNVIPVEMQSHCCAXMWEFSYIGFPIXNIDXOTXTNBCHSHUZGKXFECL',
'YZBAIIOTWLREPZISBGJLQDALKZUKEQMKLDIPXJEPENEIPWFDLP',
'HBQKWJFLSEXVILKYPNSWUZLDCRTAYUUPEITQJEITZRQMMAQNLN',
'DQDJGOWMBFKAIGWEAJOISPFPLULIWVVALLIIHBGEZLGRHRCKGF',
'LXYPCVPNUKSWCCGXEYTEBAWRLWDWNHHNNNWQNIIBUCGUJYMRYW',
'CZDKISKUSBPFHVGSAVJBDMNPSDKFRXVVPLVAQUGVUJEXSZFGFQ',
'IYIJGISUANRAXTGQLAVFMQTICKQAHLEBGHAVOVVPEXIMLFWIYI',
'ZIIFSOPCMAWCBPKWZBUQPQLGSNIBFADUUJJHPAIUVVNWNWKDZB',
'HGTEEIISFGIUEUOWXVTPJDVACYQYFQUCXOXOSSMXLZDQESHXKP',
'FEBZHJAGIFGXSMRDKGONGELOALLSYDVILRWAPXXBPOOSWZNEAS',
'VJGMAOFLGYIFLJTEKDNIWHJAABCASFMAKIENSYIZZSLRSUIPCJ',
'BMQGMPDRCPGWKTPLOTAINXZAAJWCPUJHPOUYWNWHZAKCDMZDSR',
'RRARTVHZYYCEDXJQNQAINQVDJCZCZLCQWQQIKUYMYMOVMNCBVY',
'ABTCRRUXVGYLZILFLOFYVWFFBZNFWDZOADRDCLIRFKBFBHMAXX',]
s=0
for i in range(30):
for j in range(50):
#行
for x in range(j+1,50):
if(ord(mat[i][x])>ord(mat[i][j])):
s+=1
#列
for y in range(i+1,30):
if(ord(mat[y][j])>ord(mat[i][j])):
s+=1
#左上右下
for (x,y) in zip(range(j+1,50),range(i+1,30)):
if(ord(mat[y][x])>ord(mat[i][j])):
s+=1
#关键来了,根据题意从左下往右上和从右上往左下算两种方式
for (x,y) in zip(range(j-1,-1,-1),range(i+1,30)):
if(ord(mat[y][x])>ord(mat[i][j])):
s+=1
if(ord(mat[i][j])>ord(mat[y][x])):
s+=1
print(s)#52800
算式问题
s=0
for i in range(123,988):
for j in range(123,988):
k=i+j
if(k>123 and k<1000):
m=str(k)+str(i)+str(j)
if('0' not in m and len(set(m))==9):
s+=1
print(s)
微生物增值
有点没搞懂,如果同时遇到Y分裂和X吃Y,到底是X先吃Y然后Y再繁殖还是先繁殖再被吃,按理来讲结果应该不同的,不过先繁殖和先吃的代码算出来结果一样,凌乱了
x,y=10,90
for i in range(1,121):
a=x
if(i%6==0):
x*=2
if(i%2==1):
y-=a
if(i%4==0):
y*=2
print(y) #94371840
世纪末的星期
借这题再熟悉下python的datetime模块
datetime.datetime()
定义一个日期,变量为年、月、日、秒等
import datetime
start=datetime.datetime(1999,12,31)
print(start)
print(start.year)
print(start.month)
print(start.day)
输出结果:
datetime.weekday()
输出日期是星期几(0为星期一,6为星期天)
print(start.weekday())
输出结果:
datetime.timedelta()
进行时间加减的时候用这个来定义差值的单位是天、秒、微秒或者周(weeks)也行
题目
import datetime
timedelta=datetime.timedelta(days=1)
start=datetime.datetime(1999,12,31)
while(start.year<9999):
if(int(start.year)%100==99 and start.month==12 and start.day==31 and start.weekday()==6):
print(start.year)
break
start=start+timedelta
第39级台阶
用python做了这题才知道set+permutation的组合有多慢…
经典排列组合问题,用itertools的permutation+set()函数我跑了一个多小时跑了个寂寞,嘛都没有
s=0
for i in range(1,40):
for j in range(2,40,2):
if(i+j==39):
mat=[]
for x in range(i):
mat.append('1')
for y in range(j//2):
mat.append('2')
if(len(mat)%2==0):
num1=1
num2=1
k=1
start=i+j//2
end=j//2
for z in range(start,end,-1):
num1*=z
num2*=k
k+=1
s+=num1//num2
print(s)
六角填数
把六角星看成一个特别的多数组就行了,建议画个图编号
m=[2,4,5,6,7,9,10,11,12]
arr=list(pm(m))
i=0
while(1):
a=1+m[0]+m[1]+m[2]
b=m[2]+m[3]+m[4]+m[5]
c=1+m[7]+m[6]+m[5]
d=8+m[0]+m[7]+m[8]
e=8+m[1]+m[3]+3
f=3+m[4]+m[6]+m[8]
if(a==b and a==c and a==d and a==e and a==f):
print(m[1])
break
else:
i+=1
m=arr[i]