杨辉三角:
用个以为数组直接模拟就行,只是 C++ 的高精度调了好久,后来发现能用 python ,于是试着写了写:
1 dp = [] 2 3 def out(L, end): 4 for i in range(end + 1): 5 print L[i], 6 print 7 8 def clear(L, num): 9 del L[:] 10 for i in range(num): 11 L.append(0) 12 13 def solve(): 14 x = int(raw_input()) 15 if x == 0: 16 return 17 else: 18 clear(dp, x) 19 dp[0] = 1 20 for i in range(0, x): 21 dp[i] = 1 22 out(dp, end = i) 23 for j in range(i, 0, -1): 24 dp[j] += dp[j-1] 25 print 26 solve() 27 28 solve()
很少用 python 刷题,写得不是很好。
鸽兔同校:
1 # -*- coding: utf-8 -*- 2 3 def solve(): 4 try: 5 s = raw_input() 6 n, m = s.split() 7 n = int(n) 8 m = int(m) 9 if 4 * n < m or (4 * n - m) % 2 == 1 or (4 * n - m) / 2 > n: 10 print ‘Error‘ 11 else: 12 a = (4 * n - m) / 2 13 b = n - a 14 print a, b 15 solve() 16 except EOFError: 17 pass 18 solve()
感觉自己好像在做小学的数学题似的 -_-||
时间: 2024-11-05 16:37:52