码迷,mamicode.com
首页 > 其他好文 > 详细

2013 ACM/ICPC 长沙现场赛 C题 - Collision (ZOJ 3728)

时间:2014-10-09 20:32:37      阅读:317      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   sp   


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 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代码:
bubuko.com,布布扣
 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 }
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)

标签:style   blog   http   color   io   os   ar   for   sp   

原文地址:http://www.cnblogs.com/LLGemini/p/4014088.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!