第一题:跑步训练
暴力求解
答案:3880
第二题:阶乘约数
数学公式:
答案:39001250856960000
第三题:出栈次序
答案:35357670
第四题:哥德巴赫分解
答案:173
第五题:图书排列
答案 :479306
第六题:猴子分香蕉
答案:3141
第七题:稍小分数
答案:
def gcd(a, b):
if b == 0: return a
return gcd(b, a % b)
a = int(input())
b = int(input())
max_a = 0
max_b = 1
for i in range(100, 1, -1):
for j in range(i - 1, 1, -1):
if j * b < a * i and gcd(j, i) == 1:
if j * max_b > i * max_a:
max_a = j
max_b = i
break
print(max_a, max_b)
第八题:excel 地址
答案:
def convertToTitle(columnNumber):
ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
res = ''
while (columnNumber > 0):
res += ch[(columnNumber - 1) % 26]
if columnNumber > 26:
columnNumber = (columnNumber - 1) // 26
else:
break
return res[::-1]
num = int(input())
print(convertToTitle(num))
第九题:日期问题
import calendar
date, res = input().split('/'), []
for u, v, w in [[0, 1, 2], [2, 0, 1], [2, 1, 0]]:
for ex in ['19', '20']:
temp = int(ex + date[u])
if 1959 < temp < 2060:
try:
calendar.weekday(temp, int(date[v]), int(date[w]))
res.append(f"{temp}-{date[v]}-{date[w]}")
except ValueError:
pass
res = list(set(res))
res.sort(key=lambda date_: (date_[:4], date_[4:6], date_[6:]))
print(*res, sep='\n')
第十题:整数划分
def num_split(num1, num2):
if num1 == 1 or num2 == 1:
return 1
elif num1 > num2:
return num_split(num1 - num2, num2) + num_split(num1, num2 - 1)
elif num1 < num2:
return num_split(num1, num1)
else:
return 1 + num_split(num1, num1 - 1)
num = int(input())
print(num_split(num, num))
第十一题:一步之遥
答案:97
第十二题:
import math
def check():
a = 0
b = 0
tmp = row
while tmp > 0:
for i in range(1, tmp + 1):
if cnt[i] == 1:
a += 1
else:
b += 1
for i in range(2, tmp + 1):
if cnt[i - 1] == cnt[i]:
cnt[i - 1] = 1
else:
cnt[i - 1] = 2
tmp -= 1
if a == m and b == n:
return True
else:
return False
def dfs(k):
global res
if k > row:
if check():
res += 1
return
cnt[k] = 1
dfs(k + 1)
cnt[k] = 2
dfs(k + 1)
str_list = input().split(" ")
m, n = int(str_list[0]), int(str_list[1])
res = 0
cnt = [0 for _ in range(100010)]
row = int(math.sqrt(2 * (m + n)))
dfs(1)
print(res)
第十三题:七星填空
import itertools
x = [i for i in range(1, 15)]
x.remove(6)
x.remove(11)
x.remove(14)
def check(a):
num1 = a[0] + a[1] + a[2] + a[3]
num2 = 6 + a[1] + a[4] + 14
if num1 != num2:
return False
num3 = 6 + a[2] + a[5] + 11
if num2 != num3:
return False
num4 = a[3] + a[5] + a[7] + a[10]
if (num3 != num4):
return False
num5 = a[8] + a[9] + a[7] + 11
if (num4 != num5):
return True
num6 = a[6] + a[10] + a[8] + 14
if (num5 != num6):
return False
num7 = a[0] + a[4] + a[6] + a[9]
if (num6 != num7):
return False
return True
for i in itertools.permutations(x):
if check(i):
print(i[0],i[1],i[2],i[3])
break