poj:2926: Max Manhattan distance

Source: Internet
Author: User

Main topic:
give you the n number of five-dimensional coordinates, you want to ask any two points between the maximum distance between Manhattan;

Ideas:
For points I and J: Manhattan Distance: |x1-x2|+|y1-y2|+ ...
Remove the absolute value (+-x1+-y1 ...) -(+-x2+-y2 ...) and the corresponding position plus minus sign is the same
So for five-dimensional coordinates, there's a 2^5 of possibilities.
The enumeration then evaluates the maximum value

#include <cstdio>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
Double s[100009][6];
int main ()
{
    int n;
    scanf ("%d", &n);
    for (int. i=0; i<n; i++) for
        (int j=0; j<5; j + +) scanf ("%lf", &s[i][j]);
    Double ans=0;
    for (int i=0; i< (1<<5); i++)//Enumerate each of the possible
    {
        double minn=inf,maxn=-inf;
        for (int j=0; j<n; j + +)//calculates the value of each number
        {
            double t=0;
            for (int k=0; k<5; k++)
            {
                if ((1<<k) &i) t+=s[j][k];//uses bit operations to enumerate
                else t-=s[j][k];
            }
            Minn=min (minn,t);
            Maxn=max (maxn,t);
        }
        Ans=max (ans, (Maxn-minn));//This is the maximum value in the case of the former I
    }
    printf ("%.2f\n", ans);
    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.