反弹.c 793 B

123456789101112131415161718192021222324252627282930
  1. #include <stdio.h>
  2. int main() {
  3. int n, m;
  4. scanf("%d %d", &n, &m);
  5. double total_distance = 0.0; // 总路程
  6. double height_after_mth_bounce = n; // 第m次落地后的高度
  7. // 计算每次落地的情况
  8. int i;
  9. for (i = 1; i <= m; i++) {
  10. // 第i次落地时的落地距离
  11. if (i == 1) {
  12. total_distance += n; // 第一次落地时的距离
  13. } else {
  14. total_distance += height_after_mth_bounce * 2; // 加上反弹和下落的距离
  15. }
  16. // 计算第i次落地后的反弹高度
  17. height_after_mth_bounce /= 4.0;
  18. }
  19. // 输出结果,保留小数点后两位
  20. printf("%.2f\n", total_distance);
  21. printf("%.2f\n", height_after_mth_bounce);
  22. return 0;
  23. }