HDU4312 Meeting point-2)

Source: Internet
Author: User

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;}
     
    
   
  
 

 

 

 

 

??

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.