为了督促自己多刷题
3-31
题目:
代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| import datetime as dt a = dt.date(1900,1,1) def check(n): if n %2012==0 and n %3==0 and n %12==0 and str(n)[4:6]=='06': return True else: return False
x=1 while True: b = a + dt.timedelta(days=x) n = int("".join(str(b).split('-'))) if check(n): print(n) break x+=1
|
日期相关的问题一般用date库最方便,不用的话你还得判断月份对不对,日期对不对,这个月有三十天还是三十一天,这年的二月有多少天,直接用date库往上加日期,什么都不用考虑
题目:
代码:
1 2 3 4 5
| n = 4 heng = 19 shu = 21*20 print(n+heng+shu)
|
题目:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| def gcd(a, b): r = 1 while (r != 0): r = a % b a = b b = r return a
def gbs(a,b): return a * b // gcd(a,b)
lst = [float('inf')]*(2021+1) lst[1] = 0 for i in range(1, 2022): for j in range(i + 1, i + 22): if j > 2021: break lst[j] = min(lst[j], lst[i] + gbs(i, j)) print(lst[2021])
|
最短路径算法,