Pagini recente » Cod sursa (job #1507676) | Cod sursa (job #1775161) | Cod sursa (job #444834) | Cod sursa (job #2141539) | Cod sursa (job #1636397)
#include <fstream>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
struct punct
{
long double x,y;
};
punct v[100005];
bool cmp(punct a,punct b)
{
if(a.x<b.x)
return 1;
else
return 0;
}
long double dist(punct a,punct b)
{
double l;
l=(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
return sqrt(l);
}
int main()
{
ifstream f("cmap.in");
ofstream g("cmap.out");
int n,j;
f>>n;
int i;
for(i=1;i<=n;i++)
{
f>>v[i].x>>v[i].y;
}
sort(v+1,v+n+1,cmp);
long double mi,w;
mi=dist(v[1],v[2]);
for(i=3;i<=n;i++)
{
j=i-1;
while(v[i].x-v[j].x<mi and j>=1)
{
w=dist(v[i],v[j]);
if(mi>w)
mi=w;
j-=1;
}
}
g<<fixed<<setprecision(6)<<mi;
return 0;
}