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 is terminated by a line containing five zeroes.
100 100 1 1 1 200 100 5 3 4 201 132 48 1900 156 0 0 0 0 0
45.00 141.42 33.69 144.22 3.09 7967.81
水平长度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);
}
}