题解 | #求小球落地5次后所经历的路程和第5次反弹的高度#
求小球落地5次后所经历的路程和第5次反弹的高度
https://www.nowcoder.com/practice/2f6f9339d151410583459847ecc98446
from decimal import Decimal high = int(input()) # dp[i] 第i次落地经过了多少米 dp = [high * (-1) for _ in range(6)] # fantan[i] 第i次落地反弹多高 fantan = [high for _ in range(6)] for i in range(1, 6): fantan[i] = Decimal(fantan[i - 1] / 2) dp[i] = dp[i - 1] + 2 * fantan[i - 1] print(dp[5]) print(fantan[5])