http://poj.org/problem?id=1755
Test instructions: Triathlon, everyone has their own speed at each stage, is there a 3 route length not 0 design so that someone can strictly win?
We enumerate everyone wins and get the inequality group: s1/v1+s2/v2+s3/v3<s1/v1 ' +s2/v2 ' +s3/v3 ' is a three-dimensional semi-planar intersection? Then look
We divide both sides by S3.
(S1/S3) * (1/V1) + (S2/S3) * (1/V2) + (1/V3) < (S1/S3) * (1/V1 ') + (S2/S3) * (1/V2 ') + (1/V3 ')
So S1/s3 and S2/s3 become the only two variables, so that the inequality group becomes two yuan an inequality group, with a semi-planar intersection can be solved.
Note Some places:
EPS to set to 1e-16
If a person has 2 speed equal to another person, directly special to the third, do not build straight line.
#include <cmath>#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>Const Doubleeps=1e- -;Const Doubleinf=99999999;structpoint{Doublex, y; Point () {}, point (DoubleX0,Doubley0): X (x0), Y (y0) {}}p[200005];structline{point s,e;Doubleslop; Line () {} line (point S0,point E0): S (s0), E (E0) {}}l[200005],c[200005];inttot,n,v1[200005],v2[200005],v3[200005],num[200005];intSgnDoublex) { if(x>eps)return 1; if(x<-eps)return-1; return 0;}intRead () {intt=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while('0'<=ch&&ch<='9') {t=t*Ten+ch-'0'; ch=GetChar ();} returnt*F;}Double operator*(Point p1,point p2) {returnp1.x*p2.y-p1.y*p2.x;} Pointoperator-(Point p1,point p2) {returnPoint (p1.x-p2.x,p1.y-p2.y);}BOOLPdintID) { for(intI=1; i<=n;i++) if(i!=ID) {intCnt=0, ans1=0, ans2=0; if(V1[i]==v1[id]) cnt++; ElseAns1=v1[id],ans2=V1[i]; if(V2[i]==v2[id]) cnt++; ElseAns1=v2[id],ans2=V2[i]; if(V3[i]==v3[id]) cnt++; ElseAns1=v3[id],ans2=V3[i]; if(cnt==3)return 0; Else if(cnt==2){ if(ANS1<=ANS2)return 0; } Num[i]=CNT;} return 1;}voidBuildintID) {Tot=0; l[++tot].s=point (0, INF); L[tot].e=point (0,0); l[++tot].s=point (0,0); L[tot].e=point (INF,0); l[++tot].s=point (INF,0); L[tot].e=point (0, INF); for(intI=1; i<=n;i++) if(i!=ID) { if(num[i]==2)Continue; Tot++; DoubleA= ((Double) (V1[i]-v1[id])/((Double) v1[id]*V1[i]); DoubleB= ((Double) (V2[i]-v2[id])/((Double) v2[id]*V2[i]); DoubleC= ((Double) (V3[i]-v3[id])/((Double) v3[id]*V3[i]); intA=SGN (A), B=SGN (b), c=SGN (C); if(a==0) {l[tot].s.x=-1; l[tot].s.y= (-C)/C; L[tot].e.x=1; l[tot].e.y= (-C)/B; if(b>0) Std::swap (L[TOT].S,L[TOT].E); }Else if(b==0) {L[tot].s=point (-c)/a,-1); L[TOT].E=point (-C)/A,1); if(a<0) Std::swap (L[TOT].S,L[TOT].E); }Else{L[TOT].S=point (-1,-((-1) *a+c)/c); L[TOT].E=point (1,-(A+C)/c); if(b>0) Std::swap (L[TOT].S,L[TOT].E); } } for(intI=1; i<=tot;i++) L[i].slop=atan2 (l[i].e.y-l[i].s.y,l[i].e.x-l[i].s.x);} Point Inter (line p1,line p2) {Doublek1= (P2.E-P1.S) * (p1.e-p1.s); DoubleK2= (P1.E-P1.S) * (p2.s-p1.s); Doublet= (K2)/(k1+K2); Doublex=p2.s.x+ (p2.e.x-p2.s.x) *T;Doubley=p2.s.y+ (P2.E.Y-P2.S.Y) *T;returnPoint (x, y);}BOOLJud (line p1,line p2,line p3) {point P=Inter (P1,P2);return(P-P3.S) * (P3.E-P3.S) >=EPS;}BOOLCMP (line p1,line p2) {if(Fabs (p1.slop-p2.slop) <=eps)return(P1.E-P1.S) * (P2.E-P1.S) <=0; Else returnp1.slop<P2.slop;}BOOLPhi () {intCnt=1; Std::sort (L+1, L +1+tot,cmp); for(intI=2; i<=tot;i++) if(Fabs (l[i].slop-l[i-1].slop) >eps) l[++cnt]=L[i]; intL=1, r=2; c[1]=l[1];c[2]=l[2]; for(intI=3; i<=cnt;i++){ while(L<r&&jud (c[r],c[r-1],l[i]) r--; while(L<r&&jud (c[l],c[l+1],l[i]) l++; c[++r]=L[i]; } while(L<r&&jud (c[r],c[r-1],C[L]) r--; while(L<r&&jud (c[l],c[l+1],C[R]) l++; if(r-l+1<3)return 0; C[r+1]=C[l]; CNT=0; for(inti=l;i<=r;i++) p[++cnt]=inter (c[i],c[i+1]); P[cnt+1]=p[1]; Doubleres=0; for(intI=1; i<=cnt;i++) Res+=p[i]*p[i+1]; Res/=2.0; Res=Fabs (RES); if(res<=eps)return 0; Else return 1; }BOOLWorkintID) {Build (ID); if(Phi ())return 1; Else return 0;}intMain () {n=read (); for(intI=1; i<=n;i++) {V1[i]=read (), V2[i]=read (), v3[i]=read (); } for(intI=1; i<=n;i++){ if(PD (i) &&work (i)) puts ("Yes"); ElsePuts"No"); } return 0;}
POJ 1755 Triathlon