题解 | #计算小球走过的路程和反弹高度#
计算小球走过的路程和反弹高度
https://www.nowcoder.com/practice/ac674f68367149d5ad1f857a379e69c9
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
// 下落的高度和落地的次数
double h;
int n;
cin >> h;
cin >> n;
// write your code here......
double height=0.0, dist =0.0;
height = h;
for( int i = 1; i < n; i++)
{
height /= 2.0;
dist += height + height*2.0;
}
dist += height;
height /= 2.0;
//cout << dist << " " << height << endl;
printf("%.1f %.1f",dist, height);
return 0;
}
总共n次回弹,每次回弹都是前一次高度的1.5倍,但最后一次回弹后,还多了一个回弹高度的落地距离
美的集团公司福利 813人发布