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