DoubleEPS = 1e-Ten;structp{Doublex, y; P (Doublex=0,Doubley=0): X (x), Y (y) {}DoubleAddDoubleADoubleb) { if(ABS (A+B) <eps* (ABS (a) +abs (b)))return 0; returnA +b; } Poperator+(P p) {returnP (Add (x, p.x), add (y, p.y)); } Poperator-(P p) {returnP (Add (x,-p.x), add (Y,-p.y)); } Poperator*(Doubled) { returnP (X*d, y*d); } DoubleDot (p p) {//dot Product returnAdd (x*p.x, y*p.y); } DoubleDet (P p) {//Differential Product returnAdd (X*P.Y,-y*p.x); }}ps[10000+ -];DoubleDist (p A, p b) {returnsqrt ((b-a). dot (b-a));}BOOLCmp_x (Constp& p,Constp&q) { if(p.x!=q.x)returnP.x <q.x; returnP.y <Q.y;} Vector<P> Convex_hull (P *ps,intN) {Sort (PS, PS+N, cmp_x); intK =0;//number of convex hull verticesVector<p> QS (n2); //construction of the lower side of the convex hull for(intI=0; i<n; i++) { while(k>1&& (qs[k-1]-qs[k-2]). Det (ps[i]-qs[k-1]) <=0) k--; Qs[k++] =Ps[i]; } //construction of the upper side of the convex hull for(inti=n-2, t=k; i>=0; i--) { while(K>t && (qs[k-1]-qs[k-2]). Det (ps[i]-qs[k-1]) <=0) k--; Qs[k++] =Ps[i]; } qs.resize (k-1); returnQs;}
The Graham algorithm constructs the convex package