POJ 3304 Segments | 线段相交

#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 105
#define eps 1e-8
using namespace std;
double abs (double x)
{
    return x>0?x:-x;
}
bool dcmp(double x,double y)
{
    if (abs(x-y)<eps) return 1;
    return 0;
}
struct point
{
    double x,y;
    point () {};
    point (double _x,double _y) :
	x(_x),y(_y) {};
    /*
    point operator - (const point &a) const
	{
	    return point (x-a.x,y-a.y);
	}
    double operator * (const point &rhs) const
	{
	    return x*rhs.y-rhs.x*y;
	}
    */
    bool operator < (const point &rhs) const
	{
	    return x<rhs.x;
	}
    friend point operator + (const point &a,const point &b) {
	return point(a.x+b.x,a.y+b.y);
    }
    friend point operator - (const point &a,const point &b) {
	return point(a.x-b.x,a.y-b.y);
    }
    friend double operator * (const point &a,const point &b) {
	return a.x*b.y-a.y*b.x;
    }
    bool operator == (const point &rhs) const
	{
	    return dcmp(x,rhs.x) && dcmp(y,rhs.y);
	}
};
struct line
{
    point a,b;
}seg[N];
int T,n;
bool check (point l,point z)
{
    if (l==z) return 0;
    for (int i=1;i<=n;i++)
	 if(((l-seg[i].a)*(l-z)) *((l-seg[i].b)*(l-z)) > eps) return 0;
    return 1;
}
void solve()
{
    	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	    scanf("%lf%lf%lf%lf",&seg[i].a.x,&seg[i].a.y,&seg[i].b.x,&seg[i].b.y);
	if (n<3)
	{
	    puts("Yes!");
	    return ;
	}
	for (int i=1;i<=n;i++)
	{
	    for (int j=i+1;j<=n;j++)
		if ( check(seg[i].a,seg[j].b) ||
		     check(seg[i].b,seg[j].a) ||
		     check(seg[i].a,seg[j].a) ||
		     check(seg[i].b,seg[j].b))
		{
		    puts("Yes!");
		    return ;
		}
	}
	puts("No!");
}
int main()
{
    scanf("%d",&T);
    while (T--)
    {
	solve();
    }
    return 0;
}

 

posted @ 2017-12-08 15:52  MSPqwq  阅读(121)  评论(0编辑  收藏  举报