题解 | #求小球落地5次后所经历的路程和第5次反弹的高度#
求小球落地5次后所经历的路程和第5次反弹的高度
http://www.nowcoder.com/practice/2f6f9339d151410583459847ecc98446
#include <bits/stdc++.h>
using namespace std;
void process(int num, double& distance, double& high){
double tmp = (double)num;
for(int i = 0; i < 5; i++){
distance += tmp * 2;
tmp = tmp / 2;
}
distance = distance - (double)num;
high = tmp;
}
int main(){
int num = 0;
cin >> num;
double distance = 0.0;
double high = 0.0;
process(num, distance, high);
printf("%lf\n", distance);
printf("%lf\n", high);
return 0;
}
华为题库题解 文章被收录于专栏
牛客华为题库的题解
顺丰集团工作强度 366人发布