题解 | #求小球落地5次后所经历的路程和第5次反弹的高度#
求小球落地5次后所经历的路程和第5次反弹的高度
https://www.nowcoder.com/practice/2f6f9339d151410583459847ecc98446
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
double h;
while (cin >> h) {
double sum = 0;;
for (int i = 1; i <= 5; i++) {
sum += h;
h /= 2;
if (i == 5) {
cout << setprecision(6) << sum << endl <<
setprecision(6) << h << endl;
}
sum += h;
}
}
}
// 64 位输出请用 printf("%lld")
查看5道真题和解析