找到一条直线,与全部线段都相交。直线由线段中的两个端点组成,所以枚举一下就好了。
#include<bits/stdc++.h>
using namespace std;
const double eps=1e-8;
struct point
{
double x,y;
} a[1024];
double cross(point a,point b)
{
return a.x*b.y-b.x*a.y;
}
point operator -(point a,point b)
{
point c;
c.x=a.x-b.x;
c.y=a.y-b.y;
return c;
}
double dot(point a,point b)
{
double t=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
return t;
}
int main()
{
int _,i,flag,u,v,j,n;
double t;
scanf("%d",&_);
while(_--)
{
scanf("%d",&n);
for(i=0; i<n; i++)
scanf("%lf %lf %lf %lf",&a[i].x,&a[i].y,&a[i+n].x,&a[i+n].y);
if(n<=2) flag=1;
else
{
flag=0;
for(u=0; u<2*n; u++)
{
for(v=u+1; v<2*n; v++)
{
if(dot(a[u],a[v])<eps) continue;
for(i=0; i<n; i++)
{
t=cross(a[i]-a[u],a[v]-a[u])*cross(a[v]-a[u],a[i+n]-a[u]);
if(t>=0) continue;
else break;
}
if(i>=n) flag=1;
if(flag) break;
}
if(flag) break;
}
}
if(flag==1) printf("Yes!
");
else printf("No!
");
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/