Pagini recente » Cod sursa (job #1135412) | Cod sursa (job #1048639) | Cod sursa (job #974014) | Cod sursa (job #2955412) | Cod sursa (job #855700)
Cod sursa(job #855700)
#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;
}