题解 | #计算小球走过的路程和反弹高度#C++/for
计算小球走过的路程和反弹高度
https://www.nowcoder.com/practice/ac674f68367149d5ad1f857a379e69c9
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
// h是路程,h1是第n次弹起高度。
int n, i;
float h, l = 0, h1 = 0;
cin >> h >> n;
for (i = 0; i < n; i++) {
if (i < 1) {
l = h;
h1 = h / 2.f;
h = h / 2.f;
}
else {
l = 2 * h + l;
h = h / 2.f;
h1 = h ;
}
}
cout << fixed << setprecision(1) << l << " " << h1;
return 0;
return 0;
}
阿里云工作强度 705人发布
