2013 ACM/ICPC 长沙现场赛 C题 - Collision (ZOJ 3728)
Posted on 2014-10-09 18:15 LLGemini 阅读(226) 评论(0) 编辑 收藏 举报Collision
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 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
题意:http://blog.csdn.net/night_raven/article/details/16922749
AC代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include <sstream> 3 #include <cstdio> 4 #include <cstring> 5 #include <cmath> 6 #include <string> 7 #include <vector> 8 #include <set> 9 #include <cctype> 10 #include <algorithm> 11 #include <cmath> 12 #include <deque> 13 #include <queue> 14 #include <map> 15 #include <stack> 16 #include <list> 17 #include <iomanip> 18 using namespace std; 19 #define INF 0x7fffffff 20 #define maxn 1010 21 #define eps 1e-12 22 const double PI = acos(-1.0); 23 typedef unsigned long long ull; 24 25 double Rm, R, r, x, y, vx, vy; 26 27 28 double dis(double k, double b) 29 { 30 return fabs(b) / sqrt(k*k + 1); 31 } 32 33 int main() 34 { 35 //freopen("out.txt", "w", stdout); 36 while(~scanf("%lf%lf%lf%lf%lf%lf%lf", &Rm, &R, &r, &x, &y, &vx, &vy)) 37 { 38 if(x*vx + y*vy >= 0) //相反方向移动! 39 { 40 printf("0.000\n"); 41 continue; 42 } 43 double k, b, d1; 44 if(vx) { 45 k = vy / vx; 46 b = y - k*x; 47 d1 = dis(k, b);//运动轨迹与圆心距离 48 } 49 else d1 = fabs(x); 50 if(d1 >= R+r) { 51 printf("0.000\n"); 52 continue; 53 } 54 55 double v = sqrt(vx*vx + vy*vy); 56 57 if(d1 >= Rm+r)//不会碰撞medal 58 double len = 2*sqrt((R+r)*(R+r) - d1*d1); 59 else 60 double len = 2*(sqrt((R+r)*(R+r) - d1*d1) - sqrt((Rm+r)*(Rm+r) - d1*d1)); 61 printf("%.3lf\n", len / v); 62 } 63 return 0; 64 }
注意:
1、判断运动方向是否是朝向圆心的方向:x*vx + y*vy < 0;
2、判断运动轨迹是否会进入圆形区域:dis >= R+r;
3、判断是否会与medal碰撞:dis < Rm+r;
4、精确度问题:三位小数;