Bzoj 3210 Flower God's watering flower rally Chebyshev distance

Source: Internet
Author: User

The main topic: some points on the plane, to find a point to all points of Chebyshev distance and minimum.


Idea: And the squirrel's title is more like, but the squirrel is the point of seeking is a point in all points, and this question is not necessarily. As with that problem, the horizontal ordinate is sorted separately, and then the median count is taken. However, it is possible to have decimals, so adjust it and take the minimum value.


CODE:

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 100010using namespace std; #define MIN (a) < (b) (a):(b)) int X[max],y[max];         struct point{int x, y;        void Read (int p) {scanf ("%d%d", &x,&y);        X[P] = x + y;    Y[P] = x-y; }}point[max]; int points;    Inline long long getans (int x,int y) {long long re = 0;    for (int i = 1; I <= points; ++i) re + + ABS (X-x[i]) + ABS (Y-y[i]); return re;}    int main () {CIN >> points; for (int i = 1; I <= points; ++i) Point[i].    Read (i);    Sort (X + 1,x + points + 1);    Sort (Y + 1,y + points + 1);    int x = x[(points + 1) >> 1],y = y[(points + 1) >> 1]; if ((x&1 && y&1) | | (! (x&1) &&!        (y&1)))    cout << Getans (x, y)/2 << Endl; else cout << min (min (Getans (x + 1,y), Getans (y + 1), Min (Getans (x-1,y), Getans (x,y-1)))/2 << Endl  ;  return 0;} 


Bzoj 3210 Flower God's watering flower rally Chebyshev distance

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.