Pagini recente » Cod sursa (job #716269) | Cod sursa (job #2717370) | Cod sursa (job #2329320) | Cod sursa (job #2787106) | Cod sursa (job #717602)
Cod sursa(job #717602)
#include<cstdio>
#include<cmath>
#include<set>
#include<vector>
#include<algorithm>
#define INF 100000000000
struct point
{
int x,y;
};
struct lower_y
{
bool operator() (point A, point B)
{
return A.y<B.y;
}
};
double dist(point A, point B)
{
return sqrt((A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y));
}
bool lower_x (point A, point B)
{
return A.x<B.x;
}
int main()
{
freopen("cmap.in","r",stdin);
freopen("cmap.out","w",stdout);
int nP; scanf("%d",&nP);
std::vector<point> sweep;
for (int i=1;i<=nP;i++)
{
point tmp;
scanf("%d %d",&tmp.x,&tmp.y);
sweep.push_back(tmp);
}
std::sort(sweep.begin(),sweep.end(),lower_x);
//
float mind=INF;
std::set<point,lower_y> setEval;
for (int i=0; i<sweep.size(); i++)
{
point cur = sweep.at(i);
for (std::set<point>::iterator it=setEval.begin();it!=setEval.end();)
if (dist(cur, *it)<mind)
{
mind=dist(cur, *it);
++it;
}
else
setEval.erase(it++);
setEval.insert(cur);
}
printf("%lf", mind);
return 0;
}