题解 | #求小球落地5次后所经历的路程和第5次反弹的高度#
求小球落地5次后所经历的路程和第5次反弹的高度
https://www.nowcoder.com/practice/2f6f9339d151410583459847ecc98446
#include <iostream> using namespace std; // double f1(double init ,int cnt){ // if(cnt == 0 ) return 0; // if(cnt == 1) return init * 1.5; // else return f1(init/2,cnt-1) + init * 1.5; // } // double f2(double init ,int cnt){ // if(cnt == 0 ) return init; // else return f2(init/2,cnt-1); // } int main() { int n; cin>>n; double init=n; // double heigh=f2(init,5); // double len=f1(init,5)-heigh; // cout<<len<<endl; // cout<<heigh<<endl; cout<<2.875*init<<endl; cout<<0.03125*init<<endl; return 0; } // 64 位输出请用 printf("%lld")
很简单,只需要乘以2个常数即可。