Cod sursa(job #406037)

Utilizator PavelRazvanPavel Razvan PavelRazvan Data 1 martie 2010 09:11:03
Problema Cele mai apropiate puncte din plan Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
#include<algorithm>
#include<math.h>
using namespace std;
#define DIM 100005
struct ok
{
	int x,y;
} a[DIM];
int n,mij;
struct cmp
{
	bool operator () (const ok &x,const ok &y)
	{
		return (x.x<y.x);
	}
};
inline void read ()
{
	int i;
	scanf("%d",&n);
	for(i=1;i<=n;++i)
		scanf("%d%d",&a[i].x,&a[i].y);
}
inline double dist(ok x,ok y)
{
	return (double)sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));
}
inline double search (int st,int dr)
{
	int i,j;
	double cmm=1<<30;
	for(i=st;i<=dr;++i)
		for(j=st;j<i;++j)
			cmm=min(cmm,dist(a[i],a[j]));
	return (double)cmm;
}
inline void solve ()
{
	mij=(1+n)/2;
	int i,j;
	for(i=mij,j=mij;;++i,--j)
	{
		if(a[i].x!=a[mij].x)
			mij=i-1;break;
		if(a[j].x!=a[mij].x)
			mij=j;break;
	}
}
int main ()
{
	freopen("cmap.in","r",stdin);
	freopen("cmap.out","w",stdout);
	read ();
	sort(1+a,1+a+n,cmp ());
	solve ();
	printf("%lf",min(min(search(1,mij),search(mij+1,n)),dist(a[mij],a[mij+1])));
	return 0;
}