题解 | 计算小球走过的路程和反弹高度
数学方法
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
// 下落的高度和落地的次数
double h;
int n;// 反弹次数
cin >> h;
cin >> n;
// write your code here......
cout << fixed << setprecision(1)
<< h * (3 - 1 / pow(2, n - 2)) << " "
<< h / pow(2, n)
<< endl;
return 0;
}
第 n 次掉落,反弹高度: h / (2^n)
第 n 次掉落,总路程 = h / (2^0) + 2 * h / (2^1) + 2 * h / (2^2) + ... + 2 * h / (2^(n-1)),等比数列求和化简