zoj 3728 Collision 计算几何

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 (xy) and initial speed vector (vxvy) 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 RmRrxyvx and vy in one line. Here 1 ≤ Rm < R ≤ 2000, 1 ≤ r ≤ 1000, R + r < |(xy)| ≤ 20000, 1 ≤ |(vxvy)| ≤ 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://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3728

题目大意:给一个以原点(0,0)为圆心,半径为Rm固定的圆饼【实心】。给一个以原点(0,0)为圆心,半径为R的大圆【空心】。有一个圆硬币,圆心为(x,y),半径为r,速度为vx,vy,硬币碰到圆饼后会以同样的能量从反射方向弹回。求硬币从进入大圆开始到离开大圆所花的时间。

思路:

1.先把圆饼和大圆的半径都加上硬币的半径,这样就可以把硬币看成是一个点。
假设硬币在A点,原点为B点,运动方向向量为AC。
2.如果向量AB,AC夹角是钝角,肯定不会经过大圆。
判定夹角——点积【点积是一个向量在另一个向量上的投影乘以另一个向量】
cos(a,b)=( 向量a * 向量b ) / (| a | * | b |) 
          =   x1*x2 + y1*y2    / (| a | * | b |)
3.然后用叉积求出AB在AC方向上距离(高)d
|c|=|a×b|=|a||b|sin<a,b> = x1*y2-x2*y1
d = sin<a,b> * AB = (x1*y2-x2*y1) / (AB * AX) * AX  
或者,设点(x0,y0),直线ax+by+c=0则距离为d=(ax0+by0+c)/根号下(a^2+b^2)
4.
如果d>R 与大圆无交点
如果Rm<d<R说明是直线穿过大圆(在大圆里面的运行距离为2*sqrt(R*R-d*d) )
如果d<Rm说明先射向圆饼然后反弹(在大圆里的运行距离为2*(sqrt(R*R-d*d)-sqrt(Rm*Rm-d*d) )

AC代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 using namespace std;
 6 const double eps = 1e-6;
 7 double Rm, R, r, x, y, vx, vy;
 8 double get_H(){
 9     if(fabs(vx) < eps)
10         return fabs(x);
11     if(fabs(vy) < eps)
12         return fabs(y);
13     double k = vy / vx;
14     double c = y - k * x; // k * x - y + c = 0;
15     double h = c / sqrt(k * k + 1);
16     return fabs(h);
17 }
18 int main(){
19     while(~scanf("%lf%lf%lf%lf%lf%lf%lf", &Rm, &R, &r, &x, &y, &vx, &vy)){
20         double h = get_H();
21         double ans = 0.0;
22         double V = sqrt(vx * vx + vy * vy);
23         if(x * vx + y * vy > eps){
24             ans = 0.0;
25         }
26         else if(h - R - r > eps){
27             ans = 0.0;
28         }
29         else if(h - Rm - r > eps){
30             ans = sqrt( (R+r) * (R+r) - (h * h) ) * 2.0;
31         }
32         else if(h - Rm - r < eps){
33             ans  = sqrt( (R+r) * (R+r) - (h * h) ) * 2.0 - sqrt( (Rm+r) * (Rm+r) - (h * h) ) * 2.0;
34         }
35         printf("%.3lf\n",ans / V);
36     }
37     return 0;

38 } 

posted @ 2015-07-29 20:15  gaoxiang36999  阅读(380)  评论(0编辑  收藏  举报