<>A卡片

cards = [2021]*10 i = 1 while True: s = str(i) for j in s: cards[int(j)] -= 1
flag= False for j in cards: if j < 0: flag = True break if flag: break i += 1
print(i-1) # 3181
<>B直线

cnt = 0 dots = [(i, j) for i in range(20) for j in range(21)] # 生成所有点 lines =
set() for i in range(len(dots)): for j in range(i+1, len(dots)): if dots[j][0]-
dots[i][0] != 0: x1, x2 = dots[i][0], dots[j][0] y1, y2 = dots[i][1], dots[j][1]
k= (y2-y1)/(x2-x1) b = (y1*(x2-x1)-x1*(y2-y1))/(x2-x1) # 这么写不会炸精度 lines.add((k,
b)) print(len(lines)+20) # 40257
<>C货物摆放

from math import * n = 2021041820210418 cnt = 0 fac = [] for i in range(1, int(
sqrt(n))+1): if n % i == 0: fac.append(i) fac.append(n//i) for i in fac: for j
in fac: for k in fac: if i*j*k == n: cnt += 1 print(cnt) # 2430
<>D路径

from math import * n = 2021 vis = [False]*(n+1) dis = [float('inf')]*(n+1)
graph= [[float('inf') for i in range(n+1)] for j in range(n+1)] for i in range(1
, n+1): for j in range(1, n+1): if abs(i-j) > 21: continue graph[i][j] = lcm(i,
j) dis[1] = 0 while True: point = 0 for i in range(1, n+1): if (not vis[i]) and
dis[i] < dis[point]: point = i if point == 0: break vis[point] = True for i in
range(1, n+1): if dis[i] > dis[point]+graph[point][i]: dis[i] = dis[point]+graph
[point][i] print(dis[n]) # 10266837
<>E回路计数

2 21 − 1 2^{21}-1221−1。

21 − 1 2^{21}-1221−1，不妨记为a。回到1号我可以从2号返回，也可从3号，4号，……，21号返回。那么最终方案总数就是这20种返回的累加和：

∑ j = 2 21 f [ a ] [ j ] \sum_{j=2}^{21}f[a][j] j=2∑21​f[a][j]

def gcd(x, y): if x % y == 0: return y return gcd(y, x % y) n = 21 m = 1 << n e
= [[False]*n for _ in range(n)] # 1-21的编号映射成0-20 f = [[0]*n for _ in range(m)]
# f[i][j]表示在状态i下从1号到j号的方案数 # 状态指二进制下对应位的教学楼访问与否，转成十进制即为状态i for i in range(n):
for j in range(n): if gcd(i+1, j+1) == 1: e[i][j] = True f[1][0] = 1 #

j) & 1 == 1: # 确保该状态是访问j号的 for k in range(n): if ((i-(1 << j)) >> k) & 1 == 1
and e[k][j]: f[i][j] += f[i-(1 << j)][k] ans = 0 for i in range(1, n): ans += f[
m-1][i] print(ans) # 881012367360
<>F时间显示

time = int(input()) time %= 24*60*60*1000 h = time//(60*60*1000) time -= h*60*
60*1000 m = time//(60*1000) time -= m*60*1000 s = time//1000 print(
"{:0>2d}:{:0>2d}:{:0>2d}".format(h, m, s))
<>G杨辉三角形

def generate(tri): tmp = [1] for i in range(len(tri)-1): tmp.append(tri[i]+tri[
i+1]) tmp.append(1) return tmp n = int(input()) res = 0 tri = [1] while True: if
nin tri: res += tri.index(n)+1 break res += len(tri) tri = generate(tri) print(
res) # 运行超时，40分
<>H左孩子右兄弟

n = int(input()) tree = [[] for i in range(n+1)] for i in range(2, n+1): tree[
int(input())].append(i) def dfs(i): if len(tree[i]) == 0: return 0 maxn = 0 for
jin tree[i]: maxn = max(maxn, dfs(j)) return len(tree[i])+maxn print(dfs(1)) #
90分
<>I异或数列

<>J括号序列

Toolsou
API参考文档