[问题] KS Round B 2020 Wandering Robot

楼主: wheels   2020-04-29 18:03:34
问题在此:https ://ppt.cc/fpuYHx
按照 Analysis 的解法写了以下 Python 3 的 code,
题目的 Sample 都跑得过,但就是 WA,
想请问有什么地方出错了吗?感谢!
import math
for t in range(1, int(input()) + 1):
W, H, L, U, R, D = map(int, input().split())
p = 0.0
while 0 < L - 1 and D + 1 <= H:
L -= 1
D += 1
exp = math.log2(math.factorial(L + D - 2))
exp -= math.log2(math.factorial(L - 1))
exp -= math.log2(math.factorial(D - 1))
exp -= L + D - 2
p += 2 ** exp
while R + 1 <= W and 0 < U - 1:
U -= 1
R += 1
exp = math.log2(math.factorial(U + R - 2))
exp -= math.log2(math.factorial(U - 1))
exp -= math.log2(math.factorial(R - 1))
exp -= U + R - 2
p += 2 ** exp
print('Case #{}: {}'.format(t, p))
楼主: wheels   2020-04-29 18:20:00
后来发现原来最后一行和最后一列的算法不一样 lolAnalysis 里面提到留给读者自行练习,就被忽略了XD

Links booklink

Contact Us: admin [ a t ] ucptt.com