题解 | #小球走过路程计算# 等比数列通项公式和求和公式
小球走过路程计算
https://www.nowcoder.com/practice/ddbb7021c0a7452f9044564234616913
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); float h=scanner.nextFloat(); int n =scanner.nextInt(); //write your code here...... double hLast = Math.pow(0.5,n) * h; double total = h * (1-Math.pow(0.5,n)) / 0.5 *2 -h; System.out.println(String.format("%.3f", hLast)+" "+String.format("%.3f", total)); //输出格式为:System.out.println(String.format("%.3f", h)+" "+String.format("%.3f", sum)); } }
特殊之处在于,第一次落地之后的落地路程都需要乘2,所以整体乘2 - 起始高度