Cod sursa(job #855702)

Utilizator Victor10Oltean Victor Victor10 Data 15 ianuarie 2013 15:21:43
Problema Cele mai apropiate puncte din plan Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 1.16 kb
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <ctime>
#include <cmath>
#define max 500000

using namespace std;

struct xy
{
    long long x, y;
} pct [100005];
xy pct1, pct2;

int main()
{
    srand ( time(NULL) );

    ifstream f ("cmap.in");
    ofstream g ("cmap.out");
    int n, i, nrc, nrc2;
    long double x1x2pat, y1y2pat, r, answ = 99999999999.8;
    f >> n;

    for (i = 1; i <= n; ++ i)
        f >> pct [i] . x >> pct [i] . y;

    for (i = 1; i <= max; ++ i)
    {
        nrc = rand () % n + 1;
        nrc2 = rand () % n + 1;
        pct1 . x = pct [nrc] . x;
        pct1 . y = pct [nrc] . y;
        nrc2 = rand () % n + 1;
        while (nrc == nrc2) nrc2 = rand () % n + 1;
        pct2 . x = pct [nrc2] . x;
        pct2 . y = pct [nrc2] . y;

        x1x2pat = (pct2 . x - pct1 . x) * (pct2 . x - pct1 . x);
        y1y2pat = (pct2 . y - pct1 . y) * (pct2 . y - pct1 . y);
        r = sqrt (x1x2pat + y1y2pat);
        //cout << r << endl;
       // g << x1x2pat << endl << y1y2pat << endl;
        if (r < answ) answ = r;

    }
    g . precision (30);
    g <<  answ;

    return 0;
}