HDU 5572 2015 上海区域赛 A题 计算几何(碰撞反弹)

题意:给一个圆和圆外两点A、B,在A以给定的速度(方向)出发,若碰到圆则发生完全弹性碰撞,问能否经过B。题解:把b点对称过去,判断与a点斜率是否等于v,然后考虑一些特殊情况,比如射线交不到圆,经过b点再交圆等,最后ok函数要写好。。。#include #include #include #include #include #include #include #include
摘要由CSDN通过智能技术生成

题意:给一个圆和圆外两点A、B,在A以给定的速度(方向)出发,若碰到圆则发生完全弹性碰撞,问能否经过B。

题解:把b点对称过去,判断与a点斜率是否等于v,然后考虑一些特殊情况,比如射线交不到圆,经过b点再交圆等,最后ok函数要写好。。。

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define L(i) i<<1
#define R(i) i<<1|1
#define INF  0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-9
#define maxn 200010
#define MOD 1000000007

int n,k;

struct Point
{
    double x, y;
    Point( double x = 0, double y = 0 ):x(x), y(y) { }
}a,b,st;
typedef Point Vector;
Vector v,vv;

struct Circle
{
    Point c;
    double r;
    Circle(){}
    Circle(Point c,double r):c(c),r(r){}
    Point point(double a)
    {
        return Point(c.x + cos(a)*r,c.y + sin(a)*r);
    }
}c;

struct Line
{
    Point p;
    Vector v;
    double ang;
    Line(){}
    Line(Point p,Vector v):p(p),v(v)
    {
        ang = atan2(v.y,v.x);
    }
    Point point(double t)
    {
        return Point(p.x+v.x*t,p.y+v.y*t);
    }
    bool operator < (const Line& L) const
    {
        return ang < L.ang;
    }
};

Vector operator+( Vector A, Vector B )       //向量加
{
    return Vector( A.x + B.x, A.y + B.y );
}

Vector operator-( Vector A, Vector B )       //向量减
{
    return Vector( A.x - B.x, A.y - B.y );
}

Vector operator*( Vector A, double p )      //向量数乘
{
    return Vector( A.x * p, A.y * p );
}

Vector operator/( Vector A, double p )      //向量数除
{
    return Vector( A.x / p, A.y / p );
}

bool operator<( const Point& A, const Point& B )   //两点比较
{
    return A.x < B.x || ( A.x == B.x && A.y < B.y );
}

int dcmp( double x )    //控制精度
{
    if ( fabs(x) < eps )
        return 0;
    else
        return x < 0 ? -1 : 1;
}

bool operator==( const Point& a, const Point& b )   //两点相等
{
    return dcmp( a.x - b.x ) == 0 && dcmp( a.y - b.y ) == 0;
}

double Dot( Vector A, Vector B )    //向量点乘
{
    return A.x * B.x + A.y * B.y;
}

double Length( Vector A )           //向量模
{
    return sqrt( Dot( A, A ) );
}

double Angle( Vector A, 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值