题解 | 求小球落地5次后所经历的路程和第5次反弹的高度

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
    let h = parseFloat(await readline());
    let totalDistance = h; // 初始下落的路程
    let reboundHeight = h / 2; // 第一次反弹的高度

    for (let i = 1; i < 5; i++) {
        totalDistance += 2 * reboundHeight; // 每次反弹后下落的路程
        reboundHeight /= 2; // 下一次反弹的高度
    }

    console.log(totalDistance); // 输出总路程
    console.log(reboundHeight); // 输出第五次反弹的高度
})();

全部评论

相关推荐

一只代码牛:应该不是你的问题,我感觉应该是最近不缺人
我的求职进度条
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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