#include<stdio.h>
int a[100010];
struct node
{
double x,y;
}start[100010],end[100010];
double direction(struct node p1,struct node p2,struct node p)
{
return (p1.x-p.x)*(p2.y-p.y)-(p1.y-p.y)*(p2.x-p.x);
}
bool is_on_segment(struct node p1,struct node p2,struct node p)
{
double min,max;
if(p1.x<p2.x)
{
max=p2.x;
min=p1.x;
}
else
{
max=p1.x;
min=p2.x;
}
if(p.x<=max&&p.x>=min)
return true;
else
return false;
}
bool interesect_segment(struct node p1,struct node p2,struct node p3,struct node p4)
{
double d1=direction(p1,p2,p3);
double d2=direction(p1,p2,p4);
double d3=direction(p3,p4,p1);
double d4=direction(p3,p4,p2);
if(d1*d2<0&&d3*d4<0)
return true;
if(d1==0&&is_on_segment(p1,p2,p3)==true)
return true;
if(d2==0&&is_on_segment(p1,p2,p4)==true)
return true;
if(d3==0&&is_on_segment(p3,p4,p1)==true)
return true;
if(d4==0&&is_on_segment(p3,p4,p2)==true)
return true;
return false;
}
int main()
{
int n,i,j,k;
while(scanf("%d",&n)!=EOF)
{
if(n==0)
break;
for(i=0;i<n;i++)
scanf("%lf%lf%lf%lf",&start[i].x,&start[i].y,&end[i].x,&end[i].y);
k=0;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(interesect_segment(start[i],end[i],start[j],end[j])==true)
break;
}
if(j==n)
a[k++]=i+1;
}
printf("Top sticks: ");
for(i=0;i<k;i++)
{
if(i==k-1)
printf("%d.\n",a[i]);
else
printf("%d, ",a[i]);
}
}
return 0;
}
#include<stdio.h>
int a[100010];
#define EPS 1e-9
struct node
{
double x,y;
}start[100010],end[100010];
double direction(struct node p1,struct node p2,struct node p)
{
return (p1.x-p.x)*(p2.y-p.y)-(p1.y-p.y)*(p2.x-p.x);
}
bool interesect_segment(struct node p1,struct node p2,struct node p3,struct node p4)
{
double d1=direction(p1,p2,p3);
double d2=direction(p1,p2,p4);
double d3=direction(p3,p4,p1);
double d4=direction(p3,p4,p2);
if(d1*d2<=EPS&&d3*d4<=EPS)
return true;
return false;
}
int main()
{
int n,i,j,k;
while(scanf("%d",&n)!=EOF)
{
if(n==0)
break;
for(i=0;i<n;i++)
scanf("%lf%lf%lf%lf",&start[i].x,&start[i].y,&end[i].x,&end[i].y);
k=0;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(interesect_segment(start[i],end[i],start[j],end[j])==true)
break;
}
if(j==n)
a[k++]=i+1;
}
printf("Top sticks: ");
for(i=0;i<k;i++)
{
if(i==k-1)
printf("%d.\n",a[i]);
else
printf("%d, ",a[i]);
}
}
return 0;
}
hdu 1147
最新推荐文章于 2019-03-18 20:48:45 发布