Collision
Time Limit: 2 Seconds
Memory Limit: 65536 KB
Special Judge
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
Author: FAN, Yuzhe
Contest: The 2013 ACM-ICPC Asia Changsha Regional Contest
题目链接 :http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3728
题目大意 :有一个圆硬币半径为r,初始位置为x,y。速度矢量为vx。vy,有一个圆形区域(圆心在原点)半径为R。另一个圆盘(圆心在原点)半径为Rm (Rm < R),圆盘固定不动,硬币撞到圆盘上会被反弹,不考虑能量损失。求硬币在圆形区域内运动的时间。
题目分析 :设硬币的运动方程为x‘ = x + vxt。y‘ = y + vyt,分别带入以(r + R) 和 (r + Rm)为半径的圆方程,与大圆联立无解或者有负解则为0,与大圆联立有无负解与小圆联立无解则直接解为(t2- t1)可用韦达定理处理。|t2 - t1| = sqrt(derta) / a,若与小圆联立有负解则为0,否则解为2*(t‘),t‘为先撞到圆盘时的t
#include <cstdio> #include <cmath> int main() { double Rm, R, r, x, y, vx, vy; while(scanf("%lf %lf %lf %lf %lf %lf %lf", &Rm, &R, &r, &x, &y, &vx, &vy) != EOF) { double a = vx * vx + vy * vy; double b = 2 * (x * vx + y * vy); double c1 = x * x + y * y - (R + r) * (R + r); double c2 = x * x + y * y - (Rm + r) * (Rm + r); double derta1 = b * b - 4 * a * c1; double derta2 = b * b - 4 * a * c2; double t1 = (-b + sqrt(derta2)) / (2 * a); double t2 = (-b - sqrt(derta2)) / (2 * a); double t3 = (-b + sqrt(derta1)) / (2 * a); double t4 = (-b - sqrt(derta1)) / (2 * a); if(derta1 <= 0) printf("0.000\n"); else if(derta1 > 0 && derta2 <= 0) { if(t3 < 0 || t4 < 0) printf("0.000\n"); else printf("%.3f\n", sqrt(derta1) / a); } else if(derta2 > 0) { double t11 = fabs(t1 - x) > fabs(t2 - x) ? t2 : t1; double t22 = fabs(t3 - x) > fabs(t4 - x) ? t4 : t3; if(t11 < 0 || t22 < 0) printf("0.000\n"); else printf("%.3f\n", 2 * fabs(t22 - t11)); } } }