枚举每根STICKS后面放的于其是否有焦点.
还有种VECTOR的写法,没搞出来....
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
const double INF = 1e-8;
int dcmp(double t){
if(fabs(t) < INF) return 0;
if(t < 0) return -1;
return 1;
}
struct point{
double x ,y;
point (double a = 0,double b = 0){
x = a;y = b;
}
};
typedef point Vector;
point operator - (const point &a,const point &b){
return point(a.x - b.x , a.y - b.y);
}
double cross(point &p,point &l1,point &l2){
return ((l1.x - p.x)*(l2.y - p.y) - (l1.y - p.y)*(l2.x - p.x));
}
double cross(Vector a,Vector b){
return a.x * b.y - a.y * b.x;
}
struct segment{
point s,e;
int number;
segment(point a,point b,int n){s = a; e = b;number = n;}
segment(){
s = point(0,0);e = point(0,0);number = 0;}
};
segment p[1001000];
bool SegmentItersection(point a1, point a2, point b1, point b2)
{
double c1 = cross(a2-a1, b1-a1), c2 = cross(a2-a1, b2-a1),
c3 = cross(b2-b1, a1-b1), c4 = cross(b2-b1, a2-b1);
return dcmp(c1)*dcmp(c2) < 0 && dcmp(c3)*dcmp(c4) < 0;
}
int pcount = 0;
int n;
bool flag [1000010];
int main()
{
int n , topsize;
double x1,x2,y1,y2;
segment temp(point(0,0),point(0,0),0);
int temp1;
while(1){
scanf("%d",&n);
if(n ==0 ) return 0;
memset(flag,0,sizeof(flag));
for(int i = 0 ;i < n; i++)
scanf("%lf%lf%lf%lf",&p[i].s.x,&p[i].s.y,&p[i].e.x,&p[i].e.y);
for(int i = 0 ;i < n ;i++)
for(int j = i + 1 ; j < n; j++)
if(SegmentItersection(p[i].e,p[i].s,p[j].e,p[j].s))
{
flag [i] =true;
break;
}
printf("Top sticks: ");
for(int i = 0; i < n; i++)
if(flag[i]==0)
{
if(i==n-1)
printf("%d.\n",i+1);
else
printf("%d, ",i+1);
}
}
return 0;
}