Approximate test instructions:
There are n integer points on the plane, asking how many steps you have at least to be able to tightly surround all the points.
Tightly surround the points that require you to walk completely around the given point and not a bit on the path
You can only go the whole points, and the direction is only up and down left and right down 8 directions, each move one grid.
Answer
The convex hull of the point is constructed first, and the answer is the summation and +4 of each side Max (ABS (X1-X2), ABS (Y1-Y2));
#include <cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<queue>#include<Set>#include<map>#include<stack>#include<time.h>#include<cstdlib>#include<cmath>#include<list>using namespacestd;#defineMAXN 100100#defineEPS 1e-9#definefor (I,A,B) for (int i=a;i<=b;i++)#defineFore (I,A,B) for (int i=a;i>=b;i--)#defineLson l,mid,rt<<1#defineRson mid+1,r,rt<<1|1#defineMKP Make_pair#definePB Push_back#defineCR Clear ()#defineSZ size ()#defineMet (b) memset (A,b,sizeof (a))#defineIossy Ios::sync_with_stdio (False)#defineFre Freopen#definePi ACOs (-1.0)#defineINF 1e6+7#defineVector PointConst intmod=1e9+7; typedef unsignedLong LongUll;typedefLong Longll;intDCMP (Doublex) { if(Fabs (x) <=eps)return 0; returnx<0?-1:1;}structpoint{Doublex, y; Point (Doublex=0,Doubley=0): X (x), Y (y) {}BOOL operator< (ConstPoint &a)Const{ if(x==a.x)returny<a.y; returnx<a.x; } Pointoperator- (ConstPoint &a)Const{ returnPoint (x-a.x,y-a.y); } Pointoperator+ (ConstPoint &a)Const{ returnPoint (x+a.x,y+a.y); } Pointoperator* (Const Double&a)Const{ returnPoint (x*a,y*a); } Pointoperator/ (Const Double&a)Const{ returnPoint (x/a,y/a); } voidRead () {scanf ("%LF%LF",&x,&y); } void out() {cout<<"Debug:"<<x<<" "<<y<<Endl; } BOOL operator== (ConstPoint &a)Const{ returnDCMP (x-a.x) = =0&& dcmp (y-a.y) = =0; }};DoubleDot (Vector a,vector b) {returna.x*b.x+a.y*b.y;}Doubledis (Vector a) {returnsqrt (Dot (a,a));}DoubleCross (point A,point b) {returna.x*b.y-a.y*b.x;}intConvexhull (Point *p,intN,point *ch) { intm=0; For (I,0, N-1) { while(m>1&& Cross (ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0) m--; Ch[m++]=P[i]; } intk=L; Fore (I,n-2,0){ while(M>k && Cross (ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0) m--; Ch[m++]=P[i]; } if(n>1) m--; returnm;}BOOLCMP (point A,point b) {returna.y<b.y;}intn,m; Point p[100005]; Point ch[100005];voidsolve () {cin>>N; intans=0; For (I,0, N-1) P[i].read (); Sort (p,p+N); M=Convexhull (P,N,CH); For (I,0, M-1) {Point TP=ch[(i+1)%m]-Ch[i]; Ans+=Max (ABS (tp.x), ABS (TP.Y)); } cout<<ans+4<<Endl;}intMain () {//fre ("In.txt", "R", stdin); intt=0; Solve (); return 0;}
View Code
[CODEFORCES50C] Happy Farm 5 Convex bag