题目链接
题目大意
按顺序丢一些小木棍,问你在最上面的是那些小木棍
解题思路
每一个小木棍都枚举在他之后丢的木棍,如果有和它相交的,他就不是最上面的。
我真的佛了,1e5的数据,枚举竟然过了…
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int N=1e5+5;
double eps=1e-8;
struct node
{
double x,y;
node(){}
node(double X,double Y)
{
x=X;y=Y;
}
int operator == (const node &a)
{
return a.x==x&&a.y==y;
}
node operator - (const node &a)
{
return node(x-a.x,y-a.y);
}
};
node e[N];
struct line
{
node x,y;
line(){}
line(node X,node Y)
{
x=X;y=Y;
}
};
line l[N];
int n;
int vis[N];
double cross(node a,node b)
{
return (a.x*b.y)-(a.y*b.x);
}
int sgn(double x)
{
if(fabs(x) < eps)return 0;
if(x < 0) return -1;
else return 1;
}
int F(line a,line b)
{
if(a.x==b.x||a.x==b.y||a.y==b.x||a.y==b.y)//判断端点重合
return 0;
return
max(a.x.x,a.y.x) >= min(b.x.x,b.y.x) &&
max(b.x.x,b.y.x) >= min(a.x.x,a.y.x) &&
max(a.x.y,a.y.y) >= min(b.x.y,b.y.y) &&
max(b.x.y,b.y.y) >= min(a.x.y,a.y.y) &&
sgn(cross((b.x-a.x),(a.y-a.x)))*sgn(cross((b.y-a.x),(a.y-a.x))) <= 0 &&
sgn(cross((a.x-b.x),(b.y-b.x)))*sgn(cross((a.y-b.x),(b.y-b.x))) <= 0;
return 0;
}
int main()
{
while(~scanf("%d",&n))
{
memset(vis,0,sizeof(vis));
node a,b;
if(n==0)
break;
for(int i=1;i<=n;i++)
{
scanf("%lf %lf %lf %lf",&a.x,&a.y,&b.x,&b.y);
l[i]=line(a,b);
}
for(int i=1;i<n;i++)
{
for(int j=i+1;j<=n;j++)
{
if(F(l[i],l[j]))
{
vis[i]=1;
break;
}
}
}
printf("Top sticks:");
for(int i=1;i<n;i++)
{
if(!vis[i])
printf(" %d,",i);
}
printf(" %d.\n",n);
}
return 0;
}