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 (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

 

题意:一个实心圆盘,划出一个与实心圆盘共圆心的半径比圆盘大的圆,这个圆外面有一个半径为r的圆形硬币,硬币沿着(vx,vy)方向移动,当硬币碰到圆盘时,速度方向改变,输出硬币在圆形区域内的移动时间

思路:首先要把圆盘和大圆的半径都扩大r,这样就可以把硬币看成一个点了,当硬币的移动方向AC和起始点与圆盘圆心连线AO夹角为钝角时,硬币肯定不会经过大圆。利用点到直线的距离公式求出圆心O到AC的高d,如果d大于大圆半径时,硬币肯定不会进入大圆,当d大于圆盘半径且小于大圆半径,不会接触圆盘,会穿过大圆,根据勾股定理求出距离,当d小于圆盘半径时,会碰到圆盘,同理根据勾股定理求出距离,根据速度得到时间

 

#include <stdio.h>
#include <math.h>

const double eps = 1e-9;

struct Point
{
    double x,y;
};
double dotProduct(Point a,Point b)
{
    return a.x * b.x + a.y * b.y;
}
int main(void)
{
    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) {
        R += r,Rm += r;
        Point AO,AC;
        AO.x = -x,AO.y = -y;
        AC.x = vx,AC.y = vy;
        if(dotProduct(AO,AC) < eps) {
            printf("0.000\n");
        }
        else {
            double V = (sqrt(vx * vx + vy * vy));
            double d;
            if(fabs(vx) < eps) d = fabs(x);
            else if(fabs(vy) < eps) d = fabs(y);
            else {
                double k = vy / vx;
                double c = y - k * x;
                d = fabs(c / sqrt(1 + k * k));
            }
            if(d >= Rm && d < R) printf("%.3lf\n",2 * sqrt(R * R - d * d) / V);
            else if(d < Rm) printf("%.3lf\n",2 * (sqrt(R * R - d * d) - sqrt(Rm * Rm - d * d)) / V);
            else printf("0.000\n");
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值