题解 | #求小球落地5次...使用公式
求小球落地5次后所经历的路程和第5次反弹的高度
https://www.nowcoder.com/practice/2f6f9339d151410583459847ecc98446
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 等比数列求和 s(5) f(5)
int a1 = in.nextInt();
Double sum5 = a1 * (1 - Math.pow(0.5, 5)) / (1 - 0.5);
Double f5 = a1 * Math.pow(0.5, 5);
System.out.printf("%.6f\n", 2 * sum5 - a1);
System.out.printf("%.6f\n", f5);
}
}
查看4道真题和解析