题解 | #小球走过路程计算#

小球走过路程计算

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......
        

        //输出格式为:System.out.println(String.format("%.3f", h)+" "+String.format("%.3f", sum));
        /** 用数学的思想解决, 第n 次反弹为 h*(1/2)的n次方;经过的距离为 h*(3-4*0.5的n次方) */
        float distance = 0, height = 0;
        height = (float)Math.pow(0.5,n) * h;
        distance = h* (3 - 4*(float)Math.pow(0.5,n));

        System.out.println(String.format("%.3f",height)+" "+String.format("%.3f",distance));


    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务