zoj3728_Collision(简单计算几何)


///
作者:tt2767
声明:本文遵循以下协议自由转载-非商用-非衍生-保持署名|Creative Commons BY-NC-ND 3.0
查看本文更新与讨论请点击:http://blog.csdn.net/tt2767
链接被删请百度: CSDN tt2767
///


题解:这题看明白之后主要是套模板去算。
1.用点积(dot)去判断是否不经过圆
2.用叉积求出原点到直线的距离
3.两种情况:撞击后反弹 或者 不撞击
4.记得只保留3位小数

#include<sstream>
#include<string>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<math.h>
#include <iterator>
#include<map>
#include <stack>
#include<queue>
#include<set>
#include <list>
#include<functional>
#include<numeric>
using namespace std;
inline int lowbit(int x){ return x&(-x);}

struct Point
{
    double x,y;
    Point(double x,double y):x(x),y(y){}
    Point(){}
};
typedef Point Vector;

double cross(Vector a , Vector b)
{
    return a.x*b.y-a.y*b.x;
}
double dot(Vector a , Vector b)
{
    return a.x*b.x+a.y*b.y;
}
typedef  long long int LL;
const double eps = 1e-9;
const int INF = 0x3f3f3f3f ;
const long double PI = acos(0.0) * 2.0;
const int N = 100009;

int main()
{
    double Rm,R,r,x,y,vx,vy;
    while(scanf("%lf%lf%lf%lf%lf%lf%lf",&Rm,&R,&r,&x,&y,&vx,&vy)==7 )
    {
        Point p(x,y);
        Vector s(0-x,0-y),v(vx,vy);
        Rm+=r;
        R+=r;
        double vel = sqrt(v.x*v.x+v.y*v.y);
        double d = fabs(cross(s,v))/vel;

        if(dot(s,v) < eps || d-R > eps)
            printf("0.000\n");
        else if(d - Rm > eps)
            printf("%.3lf\n",2*sqrt(R*R-d*d)/vel);
        else
            printf("%lf\n",2*( sqrt(R*R-d*d) -  sqrt(Rm*Rm-d*d) )/vel );
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值