The main idea: N points on a given plane, to find the minimum of one point in the N point to the Chebyshev distance of the n points
Chebyshev, that is, the maximum of the absolute value of each coordinate difference
First of all, if we want to convert the Manhattan distance to Chebyshev distance then we have to turn the point (x, y) into a new point (x+y,x-y) where the Chebyshev distance between the points is the Manhattan distance between the origin.
Similarly, we can convert the Chebyshev distance to Manhattan distance (x, y) into ((X+y)/2, (x-y)/2).
The horizontal ordinate sort is then maintained with the prefix and the Manhattan distance of the horizontal ordinate is discussed separately
Avoid double, finally calculate distance and divide by 2
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include < algorithm> #define M 100100#define EPS 1e-7using namespace Std;typedef long long ll;struct point{ll x,y;void Read () {int X,Y;SCANF ("%d%d", &x,&y);p oint::x=x+y;point::y=x-y;}} Points[m];int n;ll x[m],y[m],ans=1ll<<62;ll sum_x[m],sum_y[m];int main () {int i,pos;cin>>n;for (i=1;i< =n;i++) {Points[i]. Read (); x[i]=points[i].x; Y[I]=POINTS[I].Y;} Sort (x+1,x+n+1); sort (y+1,y+n+1); for (i=1;i<=n;i++) {sum_x[i]=sum_x[i-1]+x[i];sum_y[i]=sum_y[i-1]+y[i];} for (i=1;i<=n;i++) {ll temp=0;pos=lower_bound (x+1,x+n+1,points[i].x)-x;temp+= (Points[i].x*pos-sum_x[pos]) + (( Sum_x[n]-sum_x[pos])-points[i].x* (n-pos));p Os=lower_bound (Y+1,Y+N+1,POINTS[I].Y)-y;temp+= (points[i].y*pos-sum_ Y[pos]) + ((Sum_y[n]-sum_y[pos])-points[i].y* (N-pos)); Ans=min (ans,temp);} Cout<<ans/2<<endl;return 0;}
Bzoj 3170 Tjoi 2013 Squirrel Party compute geometry