题解 | #小球走过路程计算#
小球走过路程计算
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......
// 1 次落地 100 反弹 50
// 2 次落地 100 + (50 + 50) 反弹 25
// 3 次落地 100 + (50 + 50) + (25 + 25) 反弹 12.5
float sum = 0 ;
for(int i = 1 ; i<= n ;i ++){
float tem = 0 ;
if(i > 1){
h = h / 2;
tem = h;
}else{
tem = h / 2;
}
sum = sum + tem * 2 ;
}
h = h / 2;
System.out.println(String.format("%.3f", h)+" "+String.format("%.3f", sum));
}
}
