高空坠球

| October 19, 2007 13:29 | timmy | Via Original
输入一个正整数repeat (0皮球从height(米)高度自由落下,触地后反弹到原高度的一半,再落下,再反弹,……,如此反复。球在第n次反弹落地时,在空中一共经过多少距离?第n次反弹的高度是多少?(输出保留1位小数)
例:括号内是说明
输入
3  (repeat=3)
10  2  (height=10m, n=2)
4   1  (height=2m, n=1)
100 8  (height=100m, n=8)
输出
25.0 2.5  (空中经过距离为25米,第2次反弹高度为2.5米)
8.0 2.0   (空中经过距离为8米,第1次反弹高度为2米)
299.2 0.4 (空中经过距离为299.2米,第1次反弹高度为0.4米)


#include <stdio.h>
void main()
{
  int ri, repeat;
  int i, n;
  double distance, height;

  scanf("%d", &repeat);
  for(ri=1; ri<=repeat; ri++){
     scanf("%lf%d", &height, &n);
    distance=height;
    for(i=1;i<=n;i++){
      height=height/2.0;
      distance=distance+height*2;
    }
     printf("%.1f %.1f\n", distance, height);
  }
}
Program/Code » C/C++ | Comments(0) | Trackbacks(0) | Reads(258)
Add a comment
 Site URI
 Email
  Password Optional
 Nickname  *  [Register]
               

 
Emots
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
Enable HTML
Enable UBB
Enable Emots
Hidden
Remember