题解 | #计算小球走过的路程和反弹高度#
计算小球走过的路程和反弹高度
http://www.nowcoder.com/practice/ac674f68367149d5ad1f857a379e69c9
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
// 下落的高度和落地的次数
double h;
int n;
cin >> h;
cin >> n;
// 初始路径长度和回弹高度
double len = h;
double hight = h/2;
if (n == 1) cout << fixed << setprecision(1) << len << " " << hight << endl;
else{
for (int i = 1; i < n; i++){
len = len + 2 * hight;
hight = hight/2;
}
cout << fixed << setprecision(1) << len << " " << hight << endl;
}
return 0;
}