135 lines
2.1 KiB
C++
135 lines
2.1 KiB
C++
#include<cstdio>
|
|
using namespace std;
|
|
const int N=100005;
|
|
const double eps=1e-10;
|
|
int n;
|
|
bool cover[N];
|
|
struct Point
|
|
{
|
|
double x,y;
|
|
};
|
|
struct edge
|
|
{
|
|
Point a,b;
|
|
} e[N];
|
|
//inline void ce()
|
|
//{
|
|
// for(int i=1; i<=n; i++)
|
|
// {
|
|
// printf("%.0lf %.0lf %.0lf %.0lf\n",e[i].a.x,e[i].a.y,e[i].b.x,e[i].b.y);
|
|
// }
|
|
//}
|
|
inline int sign(double u)
|
|
{
|
|
if(u>=-eps&&u<=eps)
|
|
{
|
|
return 0;
|
|
}
|
|
if(u>0)
|
|
{
|
|
return 1;
|
|
}
|
|
else return -1;
|
|
}
|
|
inline double cross(Point a,Point b)
|
|
{
|
|
return a.x*b.y-b.x*a.y;
|
|
}
|
|
inline Point des(Point a,Point b)
|
|
{
|
|
a.x-=b.x;
|
|
a.y-=b.y;
|
|
return a;
|
|
}
|
|
bool max(double a,double b)
|
|
{
|
|
return a>b? a:b;
|
|
}
|
|
bool min(double a,double b)
|
|
{
|
|
return a<b? a:b;
|
|
}
|
|
//bool cmp()
|
|
inline edge maxe(edge a)
|
|
{
|
|
edge b;
|
|
b.a.x=max(a.a.x,a.b.x);
|
|
b.a.y=max(a.a.y,a.b.y);
|
|
b.b.x=min(a.a.x,a.b.x);
|
|
b.b.y=min(a.a.y,a.b.y);//b->a
|
|
return b;
|
|
}
|
|
inline bool cejiao(edge a,edge b)
|
|
{
|
|
Point yi=des(a.a,a.b);
|
|
Point er=des(b.a,a.b);
|
|
Point san=des(b.b,a.b);
|
|
int sh=sign(cross(yi,er)),ni=sign(cross(yi,san));
|
|
// printf("%d %d\n",sh,ni);
|
|
if(sh*ni<=0)
|
|
{
|
|
return 1;
|
|
}
|
|
if(sh==0||ni==0)
|
|
{
|
|
edge ma=maxe(a),mb=maxe(b);
|
|
// printf("A:%.0lf %.0lf/%.0lf %.0lf",ma.a.x,ma.a.y,ma.b.x,ma.b.y);
|
|
// printf("B:%.0lf %.0lf/%.0lf %.0lf",mb.a.x,mb.a.y,mb.b.x,mb.b.y);
|
|
// printf("%.0lf %.0lf %.0lf %.0lf\n",e[i].a.x,e[i].a.y,e[i].b.x,e[i].b.y);
|
|
if(ma.a.x>=mb.b.x&&ma.a.y>=mb.b.y)
|
|
{
|
|
if(mb.a.x>=ma.b.x&&mb.a.y>=ma.b.y)
|
|
{
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
int main()
|
|
{
|
|
// freopen("ain.txt","r",stdin);
|
|
// freopen("aout.txt","w",stdout);
|
|
while(~scanf("%d",&n))
|
|
{
|
|
if(n==0)
|
|
{
|
|
break;
|
|
}
|
|
for(int i=1; i<=n; i++)
|
|
{
|
|
scanf("%lf%lf%lf%lf",&e[i].a.x,&e[i].a.y,&e[i].b.x,&e[i].b.y );
|
|
for(int j=1; j<i; j++)
|
|
{
|
|
// printf("%d->%d(%d,%d)\n",i,j,cejiao(e[i],e[j]),cejiao(e[j],e[i]));
|
|
if(!cover[j]&&cejiao(e[i],e[j])&&cejiao(e[j],e[i]))
|
|
{
|
|
cover[j]=1;
|
|
}
|
|
}
|
|
}
|
|
printf("Top sticks: ");
|
|
int i;
|
|
for(i=1; i<=n; i++)
|
|
{
|
|
if(!cover[i])
|
|
{
|
|
printf("%d",i);
|
|
break;
|
|
}
|
|
else cover[i]=0;
|
|
}
|
|
for(i=i+1; i<=n; i++)
|
|
{
|
|
if(!cover[i])
|
|
{
|
|
printf(", %d",i);
|
|
}
|
|
else cover[i]=0;
|
|
}
|
|
printf(".\n");
|
|
// ce();
|
|
}
|
|
return 0;
|
|
}
|