hdu 4793

来源:互联网 发布:阿里云存储 价格 编辑:程序博客网 时间:2024/04/26 05:12

Description

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 medal R m, radius of coin r, 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 R m, R, r, x, y, vx and vy in one line. Here 1 ≤ R m < 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 -15 20 1 30 15 -1 0

Sample Output

30.00029.394


题目大意 :有一个圆硬币半径为r,初始位置为x,y,速度矢量为vx,vy,有一个圆形区域(圆心在原点)半径为R,还有一个圆盘(圆心在原点)半径为Rm (Rm < R),圆盘固定不动,硬币撞到圆盘上会被反弹,不考虑能量损失,求硬币在圆形区域内运动的时间。


运动方程:

x'=x+t*vx

y'=y+t*vy


只有当t1!=t2且t1,t2均大于0时才表示硬币进入到了R,否则直接输出0即可(无解或只有一解或有解小于0),然后用相同的方法判断硬币是否进入Rm,如果没有碰到,则|t1-t2|就是答案,否则计算出硬币碰到Rm的时间t3,设t1>t2,那么2*(t3-t2)即为答案(因为硬币碰到Rm后做反射运动)。


#include<iostream>#include<cstring>#include<string>#include<cmath>#include<cstdio>#include<vector>#include<stack>#include<map>#include<algorithm>#define inf 0x3f3f3f3f#define ll long longusing namespace std;int main(){    int Rm;    while(cin>>Rm)    {        int R,r,x,y,vx,vy;        cin>>R>>r>>x>>y>>vx>>vy;        double a=vx*vx+vy*vy;        double b=2*(vx*x+y*vy);        double c=x*x+y*y-(R+r)*(R+r);        double d1=b*b-4*a*c;        if(d1<=0||a==0)        {            cout<<"0.000"<<endl;            continue;        }        double t1=(-b+sqrt(d1))/(2*a),t2=(-b-sqrt(d1))/(2*a);        if(t2<0)        {            cout<<"0.000"<<endl;            continue;        }        double cc=x*x+y*y-(Rm+r)*(Rm+r);        double dx=b*b-4*a*cc;        if(dx<=0)            printf("%0.3f\n",t1-t2);        else        {            double t3=(-b+sqrt(dx))/(2*a),t4=(-b-sqrt(dx))/(2*a);            if(t4<0)                cout<<"0.000"<<endl;            else                printf("%0.3f\n",2*(t4-t2));        }    }    return 0;}



0 0