题解:模拟,distance = distance - rebound,题目是第n次落地时的距离,故rebound不能加进去。
#include <stdio.h>
int main()
{
int n;
double h, distance, rebound;
scanf("%lf %d", &h, &n);
distance = 0, rebound = 0; //n为0的时候,while不执行,所以这两个一定要赋初值。
while (n--)
{
rebound = h / 2; //反弹高度等于目前高度的一半。
distance = distance + h + rebound; //每弹一次距离为高度+反弹。
h = rebound; //新一轮高度等于上一轮反弹。
}
printf("%.1lf %.1lf", distance - rebound, rebound);
return 0;
}