NYOJ1016:德莱联盟(判线段相交)

德莱联盟

时间限制: 1000  ms  |  内存限制: 65535  KB
难度: 1
描述

欢迎来到德莱联盟。。。。

德莱文。。。

德莱文在逃跑,卡兹克在追。。。。

我们知道德莱文的起点和终点坐标,我们也知道卡兹克的起点和中点坐标,问:卡兹克有可能和德莱文相遇吗?,并且保证他们走的都是直线。


输入
几组数据,一个整数T表示T组数据
每组数据 8个实数,分别表示德莱文的起点和终点坐标,以及卡兹克的起点和终点坐标
输出
如果可能 输出 Interseetion,否则输出 Not Interseetion
样例输入

2 -19.74 7.14 22.23 -27.45 -38.79 -5.08 47.51 34.01 -8.61 9.91 -32.47 6.47 -3.81 -16.1 7.82 -6.37

样例输出

Interseetion Not Interseetion

# include <iostream>
# include <cstdio>
# include <algorithm>
using namespace std;
struct node
{
    double x, y;
}st1,st2,ed1,ed2;
double fun(node a, node b, node c)//叉乘
{
    return a.x*b.y + b.x*c.y + c.x*a.y - a.x*c.y - b.x*a.y - c.x*b.y;
}
int main()
{
    int t;
    double s1,s2,s3,s4;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&st1.x,&st1.y,&ed1.x,&ed1.y,&st2.x,&st2.y,&ed2.x,&ed2.y);
        if((max(st1.x,ed1.x)>=min(st2.x,ed2.x)||max(st2.x,ed2.x)>=min(st1.x,ed1.x))&&
           (max(st1.y,ed1.y)>=min(st2.y,ed2.y)||max(st2.y,ed2.y)>=min(st1.y,ed1.y)))//快速排斥
        {
            s1 = fun(st1, ed1, st2);//跨立
            s2 = fun(st1, ed1, ed2);
            s3 = fun(st2, ed2, st1);
            s4 = fun(st2, ed2, ed1);
            if(s1*s2<=0 && s3*s4<=0)
                puts("Interseetion");
            else
                puts("Not Interseetion");
        }
        else
            puts("Not Interseetion");
    }
    return 0;
}
参考博文:http://blog.csdn.net/LYHVOYAGE/article/details/24601151#

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值