杨辉三角:
用个一维数组直接模拟就行,只是 C++ 的高精度调了好久,后来发现能用 python ,于是试着写了写:
dp = [] def out(L, end):
for i in range(end + 1):
print L[i],
print def clear(L, num):
del L[:]
for i in range(num):
L.append(0) def solve():
x = int(raw_input())
if x == 0:
return
else:
clear(dp, x)
dp[0] = 1
for i in range(0, x):
dp[i] = 1
out(dp, end = i)
for j in range(i, 0, -1):
dp[j] += dp[j-1]
solve() solve()
很少用 python 刷题,写得不是很好。
鸽兔同校:
# -*- coding: utf-8 -*- def solve():
try:
s = raw_input()
n, m = s.split()
n = int(n)
m = int(m)
if 4 * n < m or (4 * n - m) % 2 == 1 or (4 * n - m) / 2 > n:
print 'Error'
else:
a = (4 * n - m) / 2
b = n - a
print a, b
solve()
except EOFError:
pass
solve()
感觉自己好像在做小学的数学题似的 -_-||