# include <stdio.h>
# include <string.h>
# define eps 1e-8
struct node
{
double x,y;
};
struct line
{
node a,b;
}vex[100009];
int w[100009];
int zero(double x)
{
if(x>eps) return 1;
if(x<-eps) return -1;
else return 0;
}
double cross(node a,node b,node c)
{
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
int on(node a,node b,node c)
{
double maxx=a.x>b.x?a.x:b.x;
double minx=a.x>b.x?b.x:a.x;
double maxy=a.y>b.y?a.y:b.y;
double miny=a.y>b.y?b.y:a.y;
if(c.x<=maxx&&c.x>=minx&&c.y<=maxy&&c.y>=miny)
return 1;
return 0;
}
int inser(node a,node b,node c,node d)
{
double d1=cross(a,b,c);
double d2=cross(a,b,d);
double d3=cross(c,d,a);
double d4=cross(c,d,b);
if(zero(d1*d2)==-1&&zero(d3*d4)==-1)
return 1;
if(zero(d1)==0&&on(a,b,c))
return 1;
if(zero(d2)==0&&on(a,b,d))
return 1;
if(zero(d3)==0&&on(c,d,a))
return 1;
if(zero(d4)==0&&on(c,d,b))
return 1;
return 0;
}
int main ()
{
int n,mark;
while(scanf("%d",&n)!=EOF)
{
if(n==0) break;
memset(w,0,sizeof(w));
for(int i=0;i<n;i++)
scanf("%lf%lf%lf%lf",&vex[i].a.x,&vex[i].a.y,&vex[i].b.x,&vex[i].b.y);
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(w[j]==0&&inser(vex[i].a,vex[i].b,vex[j].a,vex[j].b))
{w[i]=1;break;}
for(int i=n-1;i>=0;i--)
if(w[i]==0)
{mark=i;break;}
printf("Top sticks:");
for(int i=0;i<mark;i++)
if(w[i]==0)
printf(" %d,",i+1);
printf(" %d.\n",mark+1);
}
return 0;
}
一開始是從後往前搜的 結果不對的 看了小嬡的代碼 說是從前往後搜快一點 不懂啊 哪位好心人看見了求告訴我一聲
zoj 2551
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.