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 Rm, 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 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
大意 就是用半径为r的硬币去碰Rm的金牌,问在R范围内的时长。
本体的重点有三:1,硬币的半径处理,我是直接加到了Rm和R的上,然后硬币就成了点。
2,情况讨论,用直线到原点距离分成三种
3,就是判断方向了,方向不对直接0
代码如下:
#pragma comment(linker, "/STACK:102400000,102400000") #include "iostream" #include "cstring" #include "algorithm" #include "cmath" #include "cstdio" #include "sstream" #include "queue" #include "vector" #include "string" #include "stack" #include "cstdlib" #include "deque" #include "fstream" #include "map" using namespace std; typedef long long LL; const int INF = 0x1fffffff; const int MAXN = 1000; #define eps 1e-14 const int mod = 100000007; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 double dis(int x,int y,int vx,int vy) { return (double)abs(vx*y-vy*x)/sqrt(vx*vx+vy*vy); } int main() { //freopen("in","r",stdin); //freopen("out","w",stdout); int Rm,R,r,x,y,vx,vy; while (scanf("%d%d%d%d%d%d%d",&Rm,&R,&r,&x,&y,&vx,&vy)!=EOF) { double dis0=sqrt(x*x+y*y); double y1=y+vy/1000.0; double x1=x+vx/1000.0; if (sqrt(x1*x1+y1*y1)>dis0) printf("0.000\n");//判断方向 else { double l=dis(x,y,vx,vy); double v=sqrt(vx*vx+vy*vy); //cout<<l<<endl; Rm+=r; R+=r; if (l>=R) printf("0.000\n");//第一种未经过 else { double s0=2*sqrt(R*R-l*l); if (l>=Rm) printf("%.3lf\n",s0/v);//第二种直接穿过 else { double s1=s0-2*sqrt(Rm*Rm-l*l);//第三种碰撞发生 printf("%.3lf\n",s1/v); } } } } }