Pagini recente » Cod sursa (job #1912559) | Cod sursa (job #1822906) | Cod sursa (job #325263) | Cod sursa (job #141119) | Cod sursa (job #2199705)
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define Nmax 1000005
using namespace std;
ifstream f("cmap.in");
ofstream g("cmap.out");
struct point{
int x, y;
}v[Nmax];
int n;
double ans;
double d;
bool cmp(point a, point b)
{
return a.x<b.x;
}
double dist( point a, point b)
{
return sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));
}
int main()
{
f >> n;
for ( int i = 1 ; i <= n ; i ++ )
f >> v[i].x >> v[i].y;
sort(v+1, v+n+1, cmp);
ans=dist(v[1],v[2]);
for (int i = 1 ; i <= n ; i ++ )
{
for (int j = i-1 ; j >= 1 && v[i].x - v[j].x < ans ; j -- )
{
d = dist(v[j], v[i]);
if (ans > d)
ans = d;
}
}
g << fixed << setprecision(6) << ans;
return 0;
}