#include <stdio.h>
double calculate_length(int n) {
double length = 0;
double high = 100;
for (int i = 1; i <= n; i++) {
length += 2 * high;
high /= 2;
}
length-=100;
return length;
}
double calculate_high(int n) {
double high = 100;
for (int i = 1; i <= n; i++) {
high /= 2;
}
return high;
}
int main() {
int n;
scanf("%d", &n);
double length = calculate_length(n);
double high = calculate_high(n);
printf("length=%.4lf\nhigh=%.4lf\n", length, high);
return 0;
}
Problem Description
一个球从100m的高度自由落下,每次落地后反弹回原高度的一半