poj 2653 Pick-up sticks
#include<stdio.h> #include<math.h> #include<string.h> #define eps 1e-8 #define zero(x)(((x)>0 ? (x):(-x))<eps) struct Point { double x,y; }; struct Line { Point a,b; }line[100100],tmp; int num[100100]; double xmult(Point p1,Point p2,Point p0)//p0p1*p0p2 叉积 { return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y); } double dmult(Point p1,Point p2,Point p0)//p0p1•p0p2点积 { return (p1.x-p0.x)*(p2.x-p0.x)+(p1.y-p0.y)*(p2.y-p0.y); } int main() { int i,j,n; while(scanf("%d",&n)!=EOF&&n) { memset(num,0,sizeof(num)); for(i=0;i<n;i++) scanf("%lf%lf%lf%lf",&line[i].a.x,&line[i].a.y,&line[i].b.x,&line[i].b.y); for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(xmult(line[i].a,line[i].b,line[j].a)*xmult(line[i].a,line[i].b,line[j].b)<-eps&& xmult(line[j].a,line[j].b,line[i].a)*xmult(line[j].a,line[j].b,line[i].b)<-eps) { num[i]=1; break; } } } printf("Top sticks:"); for(i=0;i<n-1;i++) { if(!num[i])printf(" %d,",i+1); } printf(" %d.\n",n); } return 0; }