HDU4312 Meeting point-2)
Question link:
Www.bkjia.com
Given n (n <= 100000) points on the plane coordinate, select one of them to minimize the Chebyshev distance between all points and the current point.
Analysis:
Distance: Set a (x1, y1), B (x2, y2); DIS = max (| x1-x2 |, | y1-y2 |) = (| x1-x2 + y1-y2 | + | x1-x2-y1 + y2 |)/2;
We regard the coordinates of point aa as (x1 + y1, x1-y1), bb as (x2 + y2, x2-y2), which is equivalent
Rotate 45 degrees counterclockwise in the coordinate system, and increase the coordinates by 2 times.
Then, seek the newest half of the distance between the smallest Manhattan.
The Code is as follows:
#include
#include
#include
#include
#include using namespace std;typedef long long LL;const int maxn = 1e5+10;struct point{ int x,y; LL sum;}p[maxn];bool cmp1(point A,point B){ if(A.x
= 1; --i) { p[i].sum += sum - (n-i) * p[i].x; sum += p[i].x; } sum = 0; sort(p+1, p+1+n, cmp2); for (LL i = 1; i <= n; ++i) { p[i].sum += (i-1) * p[i].y -sum; sum += p[i].y; } sum = 0; LL ans = 1LL<<62; for (LL i = n; i >= 1; --i) { p[i].sum += sum - (n-i) * p[i].y; ans = min(ans, p[i].sum); sum += p[i].y; } printf(%I64d,ans/2); } return 0;}
??