试题 历届真题 天干地支【第十一届】【决赛】【A组】
这道题意外的很简单,先草稿纸推出00年是庚申年,然后就最基础的计算
tiangan = ['jia','yi','bing','ding','wu','ji','geng','xin','ren','gui']
dizhi = ['zi','chou','yin','mao','chen','si','wu','wei','shen','you','xu','hai']
# 0:庚申年 天干:6 地支:8
# 1辛酉年 天干:7 地支:9
n = int(input())
n = n%60
a = tiangan[(n % 10 + 6) %10]
b = dizhi[(n % 12 + 8) %12]
ans = a + b
print(ans)
试题 历届真题 蓝肽子序列【第十一届】【决赛】【研究生组】
思路:切割字符串为两个肽链
接着,利用dp算法求解最大公共子序列。公共子序列原来是一种经典的dp问题,可怜我绞尽脑汁想方法也想不出来,哎。
s1 = input()
s2 = input()
l1 = list(s1)
l2 = list(s2)
mark1 = []
mark2 = []
for i in range(len(s1)):
if l1[i].islower():
pass
else:
mark1.append(i) # 标记大写位置
for i in range(len(s2)):
if l2[i].islower():
pass
else:
mark2.append(i) # 标记大写位置
# 取肽分子
tai1 = []
tai2 = []
# 1
for i in range(len(mark1)):
tmp = ''
if i<len(mark1)-1:
for j in range(mark1[i],mark1[i+1]):
tmp += l1[j]
tai1.append(tmp)
else:
for j in l1[mark1[i]:]:
tmp += j
tai1.append(tmp)
# 2
for i in range(len(mark2)):
tmp = ''
if i<len(mark2)-1:
for j in range(mark2[i],mark2[i+1]):
tmp += l2[j]
tai2.append(tmp)
else:
for j in l2[mark2[i]:]:
tmp += j
tai2.append(tmp)
n = len(tai1)
m = len(tai2)
dp = [[0 for i in range(m+1)] for i in range(n+1)]
for i in range(1,n+1):
for j in range(1,m+1):
if tai1[i-1] == tai2[j-1]:
dp[i][j] = dp[i-1][j-1] + 1
else:
dp[i][j] = max(dp[i-1][j],dp[i][j-1])
print(dp[n][m])