Anonymous Anonymous - 18 days ago
874 0

No description

C++

Kedekatan

#include <iostream>
#include <cmath>
using namespace std;

int hasil(int xj, int xi, int yj, int yi, int D)
{
    return pow(abs(xj - xi), D) + pow(abs(yj - yi), D);
}

int main(int argc, char const *argv[])
{
    int N, D, x[101], y[101], max, min;
    cin >> N >> D;

    for (int i = 0; i < N; i++)
    {
        scanf("%d %d", &x[i], &y[i]);
    }
    
    max = hasil(x[0], x[1], y[0], y[1], D);
    min = hasil(x[0], x[1], y[0], y[1], D);

    // cout << max << " " << min << "\n";

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (i == j)
            {
                continue;
            }
            
            if (hasil(x[j], x[i], y[j], y[i], D) > max)
            {
                max = hasil(x[j], x[i], y[j], y[i], D);
            }
            else if (hasil(x[j], x[i], y[j], y[i], D) < min)
            {
                min = hasil(x[j], x[i], y[j], y[i], D);
            }
            
        }
        
    }
    
    cout << min << " " << max << "\n";
    return 0;
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download