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

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

https://www.nowcoder.com/practice/2f6f9339d151410583459847ecc98446

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int h;
    cin >> h;
    double distance = h;;
    vector<double> height(5);
    height[0] = (double)h / 2.0;
    
    for(int i = 1; i < 5; ++i) {
        distance += 2 * height[i-1];
        height[i] = height[i-1] / 2.0;
    }

    cout << distance << endl;
    cout << height[4] << endl;
    return 0;
}

全部评论

相关推荐

牛客96763241...:杭电✌️也是打完招呼,没人回吗
点赞 评论 收藏
分享
面了100年面试不知...:太礼貌,还是
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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