標籤:style blog http color io os ar for sp
CollisionTime 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 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 -15 20 1 30 15 -1 0
Sample Output
30.00029.394
題意:http://blog.csdn.net/night_raven/article/details/16922749
AC代碼:
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 0x7fffffff20 #define maxn 101021 #define eps 1e-1222 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)//不會碰撞medal58 double len = 2*sqrt((R+r)*(R+r) - d1*d1);59 else60 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 }View Code
注意:
1、判斷運動方向是否是朝向圓心的方向:x*vx + y*vy < 0;
2、判斷運動軌跡是否會進入圓形地區:dis >= R+r;
3、判斷是否會與medal碰撞:dis < Rm+r;
4、精確度問題:三位小數;
2013 ACM/ICPC 長沙現場賽 C題 - Collision (ZOJ 3728)