解题思路:
高度是第n次落地后再次弹起的高度,经过多少米是落地前经过的“路程”。
高度:每次弹起的高度为原来的一半,所以每次只需“/2.0”即可;
路程:将每次落地前经过的“路程”累加。例如第1次落地经过的距离为1000,第二次就为1000+500+500,第三次就为:1000+500+500+250+250
注意事项:
注意输出小数点后两位,中间有空格。
参考代码:
#include <iostream>
using namespace std;
int main(void)
{
double M, N;
double high, length=0;
cin >> M >> N;
for ( int i=0; i<N; i++ )
{
length = length + M + high;
high = (M/=2.0);
}
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << high << " " << length << endl;
return 0;
}
0.0分
0 人评分