题解 | #小球走过路程计算#
小球走过路程计算
http://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......
//输出格式为:System.out.println(String.format("%.3f", h)+" "+String.format("%.3f", sum));
double sum=0;
double o=h;
for(int i=0;i<n;i++){
/* sum+=(double)h;
h/=2;
sum+=h;*/
//第一次只有落下所以减去第一次一次的高度
sum+=2*h;
h/=2;
}
System.out.println(String.format("%.3f", h)+" "+String.format("%.3f", sum-o)); } }