There's a round medal fixed on an ideal smooth table, Fancy is trying to throw some coins and make them slip towards the medal to collide. There's also a round range which shares exact the same center as the round medal, and radius of the medal is strictly less than radius of the round range. Since that the round medal is fixed and the coin is a piece of solid metal, we can assume that energy of the coin will not lose, the coin will collide and then moving as reflect.
Now assume that the center of the round medal and the round range is origin ( Namely (0, 0) ) and the coin's initial position is strictly outside the round range. Given radius of the medalRm, radius of coinr, radius of the round range R, initial position (x,y) and initial speed vector (vx,vy) of the coin, please calculate the total time that any part of the coin is inside the round range.
Please note that the coin might not even touch the medal or slip through the round range.
Input
There will be several test cases. Each test case contains 7 integers Rm,R,r,x, y, vx and vy in one line. Here 1 ≤Rm <R ≤ 2000, 1 ≤r ≤ 1000, R +r < |(x,y)| ≤ 20000, 1 ≤ |(vx,vy)| ≤ 100.
Output
For each test case, please calculate the total time that any part of the coin is inside the round range. Please output the time in one line, an absolute error not more than 1e-3 is acceptable.
Sample Input
5 20 1 0 100 0 -1 5 20 1 30 15 -1 0
Sample Output
30.000 29.394
Author: FAN, Yuzhe
Contest: The 2013 ACM-ICPC Asia Changsha Regional Contest
题意:就是给一个圆台和圆台中央有一个固定的圆徽章,然后用一个圆形的硬币从外面以一条直线射进来,如果碰到到徽章就反弹,问你这个硬币在圆台中滑行的时间。。
思路:第一次做正式比赛的几何题。。。这道题可以分成三种情况,一,没有进入圆台所以是0,二,进入了耽美碰到徽章。三,进入了碰到徽章。。
现在主要讨论二三种情况。。看图:
第二种情况:
所以由图可知道距离为 sqrt((R+ r)*(R+ r)-(点到直线的距离的平方))*2。。。
第三种情况:
则距离为:sqrt((R+r)^2-(原点到直线的距离)^2)-sqrt((Rm+r)^2-(原点到直线的距离)^2)....
在杭电上提交的同学请注意了。好像杭电上是没有特殊判断所以要保留3位小数。。不然会wa!!!
代码:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
int rm,R,r,x,y,vx,vy;
double k,b;
double Dkb()
{
if(vx==0)
return (double)abs(x);
if(vy==0)
return (double)abs(y);
double k = vy/(double)vx;
double b = (double)y - k*x;
return fabs((double)b)/(sqrt(k*k+1));
}
int main()
{
while(~scanf("%d",&rm))
{
scanf("%d%d%d%d",&R,&r,&x,&y);
scanf("%d%d",&vx,&vy);
if(x*vx+y*vy>=0)
{
printf("0.0000\n");
continue;
}
double h = Dkb();
if(h>=R+r)
{
printf("0.0000\n");
continue;
}
double V = sqrt(vx*vx+vy*vy),ans;
if(h>=rm+r)
{
ans = 2*sqrt((R+r)*(R+r)-h*h);
printf("%0.3f\n",ans/V);
}
else
{
ans = sqrt((R+r)*(R+r)-h*h);
ans = ans - sqrt((rm+r)*(rm+r)-h*h);
ans*=2.0;
printf("%0.3f\n",ans/V);
}
}
return 0;
}