题目大意:
按顺序放上一些线段,为最后未被其他线段覆盖的线段有哪些?
解题思路:
数据很水,n2也能过,主要考察线段相交的判断。
倒着加入,看每条线段有没有与先加入的相交,没有则不被覆盖。
若两条线段相交,则其两端点分别在另一条线段两侧,用叉乘判断即可。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<ctime>
#include<vector>
#include<queue>
#define ll long long
using namespace std;
int getint()
{
int i=0,f=1;char c;
for(c=getchar();(c!='-')&&(c<'0'||c>'9');c=getchar());
if(c=='-')c=getchar(),f=-1;
for(;c>='0'&&c<='9';c=getchar())i=(i<<3)+(i<<1)+c-'0';
return i*f;
}
const int N=100005;
int n,m,ans[N];
struct point
{
double x,y;
point(){}
point(double _x,double _y):
x(_x),y(_y){}
friend inline point operator -(const point &a,const point &b)
{return point(a.x-b.x,a.y-b.y);}
friend inline double operator *(const point &a,const point &b)
{return a.x*b.y-a.y*b.x;}
};
struct node
{
point s,t;
}a[N];
bool Inter(node u,node v)
{
return ((u.t-u.s)*(v.t-u.s))*((u.t-u.s)*(v.s-u.s))<=0&&((v.t-v.s)*(u.s-v.s))*((v.t-v.s)*(u.t-v.s))<=0;
}
int main()
{
//freopen("lx.in","r",stdin);
//freopen("lx.out","w",stdout);
while(n=getint())
{
if(!n)break;
m=0;
for(int i=1;i<=n;i++)
scanf("%lf%lf%lf%lf",&a[i].s.x,&a[i].s.y,&a[i].t.x,&a[i].t.y);
for(int i=n;i;i--)
{
int bz=1;
for(int j=i+1;j<=n;j++)
if(Inter(a[i],a[j]))
{
bz=0;
break;
}
if(bz)ans[++m]=i;
}
printf("Top sticks: ");
for(int i=m;i>1;i--)printf("%d, ",ans[i]);
printf("%d.\n",ans[1]);
}
return 0;
}