#include <iostream>
#include <cstring>
#include<cmath>
#include<algorithm>
#include<vector>
const double N=-1e-10;
using namespace std;
int bz[1005];
struct point
{
double x,y;
};
vector<point> a[100005];
int xj(point x1,point x2,point x3,point x4)//相交为1,不交为0
{
if(min(x1.x,x2.x)>max(x3.x,x4.x)||min(x1.y,x2.y)>max(x3.y,x4.y)
||min(x3.x,x4.x)>max(x1.x,x2.x)||min(x3.y,x4.y)>max(x1.y,x2.y)
)
return 0;//不交:矩形排斥实验 ,最小的>最大的 肯定不交
double a,b,c,d;
a=(x1.x-x2.x)*(x3.y-x1.y)-(x1.y-x2.y)*(x3.x-x1.x);//跨立实验
b=(x1.x-x2.x)*(x4.y-x1.y)-(x1.y-x2.y)*(x4.x-x1.x);
c=(x3.x-x4.x)*(x1.y-x3.y)-(x3.y-x4.y)*(x1.x-x3.x);
d=(x3.x-x4.x)*(x2.y-x3.y)-(x3.y-x4.y)*(x2.x-x3.x);
return a*b<=N&&c*d<=N;
}
int main(void)
{
int t,i,j,s;
point s1,s2;
while(cin>>t&&t)
{ memset(bz,0,sizeof(bz));
for(i=0;i<t;i++)
{
cin>>s1.x>>s1.y>>s2.x>>s2.y;
a[i].push_back(s1);
a[i].push_back(s2);
}
for(s=i=0;i<t;i++)
{ for(j=i+1;j<t;j++)
if(xj(a[i][0],a[i][1],a[j][0],a[j][1])) break;
if(j==t) bz[s++]=i+1;//没有提前退出说明没有被覆盖
}
cout<<"Top sticks:";
for(i=0;i<s-1;i++)
cout<<' '<<bz[i]<<',';
cout<<' '<<t<<'.'<<endl;
for(i=0;i<t;i++)
a[i].clear();
}
}
poj 2653二维vector线段相交
最新推荐文章于 2021-10-04 16:06:59 发布