首页 > 其他 > 详细

51nod 1264 线段相交

时间:2016-08-07 21:21:18      阅读:330      评论:0      收藏:0      [点我收藏+]

题目:传送门

题意:给两条线段,有一个公共点或有部分重合认为相交,问他们是否相交。

题解:这属于非规范相交的情况,模板题。

#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
struct point{
    double x,y;
}a,b,c,d;
const double eps=1e-3; //精度问题
double cross(point a,point b,point c)
{
    return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}
double Across(point a,point b,point c,point d) //非规范相交
{
    double tmp=cross(c,b,a)*cross(d,b,a);
    double tmp2=cross(a,c,d)*cross(b,c,d);
    if((tmp<=0||fabs(tmp)<eps)&&(tmp2<=0||fabs(tmp2)<eps)) return true;
    return false;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y>>d.x>>d.y;
        if(Across(a,b,c,d))
        puts("Yes");
        else
        puts("No");
    }
    return 0;
}

 

51nod 1264 线段相交

原文:http://www.cnblogs.com/Ritchie/p/5746956.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!