nyistOJ 游戏AOE技能分析(1)自杀还是他杀?beta (计算几何)

抄模版1A

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#define LL long long
#define DB double

using namespace std;
const DB EPS = 1e-8;
const DB PI = acos(-1.0);
struct cpoint{
    DB x,y,R;
    void get(){scanf("%lf%lf",&x,&y);}
    void out(){cout<<x<<" "<<y<<endl;}
};
struct cvector{
    DB x,y;
    cvector(DB a=0,DB b=0){x=a;y=b;}
};
struct csegment{
    cpoint st,en;
    csegment(cpoint a,cpoint b){st=a;en=b;}
    csegment(){}
};
cvector operator-(cpoint a,cpoint b)
{
    return cvector(a.x-b.x,a.y-b.y);
}
cpoint operator+(cpoint a,cvector b)
{
    a.x+=b.x;a.y+=b.y;
    return a;
}
DB dot(cvector a,cvector b)
{
    return a.x*b.x+a.y*b.y;
}
DB length(cvector a)
{
    return sqrt(a.x*a.x+a.y*a.y);
}
DB alph;
cpoint O,M,P,A,B;
void in()
{
    O.get();M.get();
    scanf("%lf%lf",&alph,&O.R);
    P.get();scanf("%lf",&P.R);
}
DB get_angl(cpoint a,cpoint b,cpoint p)
{
    return acos(dot(a-p,b-p)/(length(a-p)*length(b-p)));
}
cpoint p2seg(cpoint p,csegment s){
    cpoint ret=s.st;
    double len = length(s.en-s.st);
    double t1=dot((p-s.st),(s.en-s.st))/len;//投影长度
     if(t1>-EPS&&t1<len+EPS){//小于线段长度
        cvector v = s.en-s.st;
        ret.x+=v.x*t1/len;ret.y+=v.y*t1/len;
        return ret;
    }
    if(t1<0) return s.st;
    else return s.en;
}
DB dist(cpoint a,cpoint b)
{
    return length(a-b);
}
cvector rotation(cvector a,double alpha){
    cvector p;
    p.x = a.x*cos(alpha)-a.y*sin(alpha);
    p.y = a.y*cos(alpha)+a.x*sin(alpha);
    return p;
}
cvector unit(cvector t)
{
    DB l = length(t);
    t.x/=l;t.y/=l;
    return t;
}
void get_AB(DB ag)
{
    cvector tmp = unit(M-O);
    tmp.x*=O.R;tmp.y*=O.R;
    A = O+rotation(tmp,ag);
    B = O+rotation(tmp,-ag);
}
void solve()
{
    DB angl = get_angl(M,P,O);
    DB ag = alph*PI/180/2;
    get_AB(ag);
    if(angl>ag)
    {
        cpoint tmp1 = p2seg(P,csegment(O,B));
        cpoint tmp2 = p2seg(P,csegment(O,A));
        DB d = min(dist(tmp1,P),dist(tmp2,P));
        if(d<P.R+EPS)
        {
            printf("1\n");
        }else
        {
            printf("0\n");
        }
    }else
    {
        DB d = dist(O,P);
        if(d<O.R+P.R+EPS)
        {
            printf("1\n");
        }else
        {
            printf("0\n");
        }
    }
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    int cas;scanf("%d",&cas);
    while(cas--)
    {
        in();
        solve();
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值