Convex bag + rotating jam modeled
C + + code:
#include <bits/stdc++.h>using namespacestd;Const intn=3e5+7;structpoint{Doublex, y; Point () {}, point (DoubleXDoubley): x (x), Y (y) {} friend pointoperator+ (ConstPoint &a,ConstPoint &b) { returnPoint (a.x + b.x, A.Y +b.y); } Friend Pointoperator- (ConstPoint &a,ConstPoint &b) { returnPoint (a.x-b.x, A.Y-b.y); } Friend Pointoperator* (ConstPoint &a,Const Double&b) { returnPoint (a.x * B, A.Y *b); } Friend Pointoperator/ (ConstPoint &a,Const Double&b) { returnPoint (a.x/b, A.Y/b); } friendBOOL operator== (ConstPoint &a,ConstPoint &b) { returna.x = = b.x && A.y = =b.y; }};DoubleR;DoubleDis (point a,point b) {returnsqrt ((a.x-b.x) * (a.x-b.x) *1.0+ (A.Y-B.Y) * (a.y-b.y));}DoubleCross (Point A,point b,point c)//Calculate fork Multiplication{ return(c.x-a.x) * (B.Y-A.Y)-(b.x-a.x) * (C.Y-a.y);}DoubleDet (Point A, point B) {returna.x * B.Y-A.Y *b.x;}DoubleDot A, point B) {returna.x * b.x + a.y *b.y;}structpolygon_convex{Vector<point>p; Polygon_convex (intSize =0) {p.resize (size); }};BOOLComp_less (ConstPoint &a,ConstPoint &b) { returnA.x-b.x <0|| a.x-b.x = =0&& A.y-b.y <0;} Polygon_convex Convex_hull (Vector<point>a) {Polygon_convex res (2* A.size () +5); Sort (A.begin (), A.end (), comp_less); A.erase (Unique (A.begin (), A.end ()), A.end ()); intm =0; for(inti =0; I < a.size (); i + +){ while(M >1&& det (res.p[m-1]-Res.p[m-2], A[i]-res.p[m-2]) <=0) --m; Res.p[m++] =A[i]; } intK =m; for(inti =int(A.size ())-2; I >=0; I--){ while(M > K && det (res.p[m-1]-Res.p[m-2], A[i]-res.p[m-2]) <=0) --m; Res.p[m++] =A[i]; } res.p.resize (M); if(A.size () >1) Res.p.resize (M-1); returnRes;} Polygon_convex A;point P[n];DoubleRotating_caliper (Point *p,intN) { intj=1; R=2*R; P[n]=p[0]; for(intI=0; i<n;i++) { while(Cross (p[i],p[i+1],p[j+1])-cross (p[i],p[i+1],P[J]) <=0) J= (j+1)%N; R=min (R,fabs (p[i],p[i+1],P[J])/dis (p[i],p[i+1])); } returnR;}intMain () {intN; scanf ("%D%LF",&n,&R); Point node; for(intI=0; i<n;i++) {scanf ("%LF%LF",&node.x,&node.y); A.p.push_back (node); } A=Convex_hull (A.P); N=a.p.size (); for(intI=0; i<n;i++) P[i]=A.p[i]; if(n<=2) printf ("0.000000000000\n"); Elseprintf ("%.12lf\n", Rotating_caliper (p,n)); return 0;}
K-blowing Candles