uva 10387 - Billiard

Problem A: Billiard

In a billiard table with horizontal side a inches and vertical side b inches, a ball is launched from the middle of the table. After s > 0 seconds the ball returns to the point from which it was launched, after having made m bounces off the vertical sides and n bounces off the horizontal sides of the table. Find the launching angle A (measured from the horizontal), which will be between 0 and 90 degrees inclusive, and the initial velocity of the ball.

Assume that the collisions with a side are elastic (no energy loss), and thus the velocity component of the ball parallel to each side remains unchanged. Also, assume the ball has a radius of zero. Remember that, unlike pool tables, billiard tables have no pockets.

Input

Input consists of a sequence of lines, each containing five nonnegative integers separated by whitespace. The five numbers are: a, b, s, m, and n, respectively. All numbers are positive integers not greater than 10000.

Input is terminated by a line containing five zeroes.

Output

For each input line except the last, output a line containing two real numbers (accurate to two decimal places) separated by a single space. The first number is the measure of the angle A in degrees and the second is the velocity of the ball measured in inches per second, according to the description above.

Sample Input

100 100 1 1 1
200 100 5 3 4
201 132 48 1900 156
0 0 0 0 0

Sample Output

45.00 141.42
33.69 144.22
3.09 7967.81

uva 10387 - Billiard_第1张图片

水平长度a,垂直高度b;经过m次垂直边上的反弹和n次水平边上的反弹后历时s秒回到出发点。一个球从桌的正中间发射,求发射时的角度(0-90度之间)和球的初始速度。运动期间无能量损失,把球看成一个质点。

所有可能的情况如上图所示:所有问题的求解可归结为求解菱形的边长和内角;

单个菱形的垂直长度为b/(2m);水平宽度为a/(2n )

tan(angle)=(bn)/(am); angle=arctan(bn/am);

总的路程就是菱形的边长总和,这样的菱形有m*n个。

边长l=sqrt((b/4M)^2+(a/4N)^2);

总路程L=4*m*n*l;

有了上述基础还不能AC,题目里有句话between 0 and 90 degrees inclusive,0(m=0)和90(n=0)是特殊情况计算路程特殊对待

还有对于第三组数据我们发现撞击次数比边长大很多时,由于精度限制l=(b*b/(4*m*m)+a*a/(4*n*n)); l会等于0;

为了避免这个问题,计算总路程L时把根号外的4*m*n化入根号内得 L=sqrt((bn)^2+(an)^2);

#include<stdio.h>
#include<math.h>
void main()
{double a,b,m,n,s,l,angle;
 while (scanf("%lf%lf%lf%lf%lf",&a,&b,&s,&m,&n)&& a+b+s+m+n)
 {angle=atan2(n*b,(m*a));
  if (m==0) l=n*b;
  else
  if (n==0) l=m*a;
  else l=sqrt(b*b*n*n+a*a*m*m);
  printf("%.2lf %.2lf\n",angle*180/3.1415926,l/s);
 }
}

 

你可能感兴趣的:(velocity,input,each,output,parallel,Numbers)