原本以為直接爆會超時ㄎㄎ
#include<cmath> #include<algorithm> #include<stdio.h> #include<vector> #include<cstring> #define MAX 100000 #define EPS 1E-8 using namespace std; class Point { public: double x,y; Point(){} Point(double _x,double _y) : x(_x),y(_y){} }; class Segment { public: Point aa,bb; Segment(){} Segment(Point _aa,Point _bb): aa(_aa),bb(_bb){} }; double GetCrossMult(const Point _A,const Point _B,const Point _O) { return (_A.x-_O.x)*(_B.y-_O.y)-(_B.x-_O.x)*(_A.y-_O.y); } bool IsIntersect(Segment sg1,Segment sg2) { return (GetCrossMult(sg2.aa, sg2.bb, sg1.aa)*GetCrossMult(sg2.aa, sg2.bb, sg1.bb)<EPS)&& (GetCrossMult(sg1.aa, sg1.bb, sg2.aa)*GetCrossMult(sg1.aa, sg1.bb, sg2.bb)<EPS); } Segment Sgs[MAX]; int Sgscnt; int main() { vector<int> tmp; while(scanf("%d",&Sgscnt)&&Sgscnt) { tmp.clear(); for(int lx=0;lx<Sgscnt;lx++) scanf("%lf %lf %lf %lf",&Sgs[lx].aa.x,&Sgs[lx].aa.y,&Sgs[lx].bb.x,&Sgs[lx].bb.y); for(int lx=0;lx<Sgscnt;lx++) { bool IsCross=false; for(int ly=lx+1;ly<Sgscnt&&!IsCross;ly++) IsCross=IsIntersect(Sgs[lx],Sgs[ly]); if(IsCross==false) tmp.push_back(lx); } printf("Top sticks:"); for(int lx=0;lx<tmp.size();lx++) printf(" %d%c",tmp[lx]+1,((lx==tmp.size()-1) ? '.':',')); printf("\n"); } return 0; }
沒有留言:
張貼留言