Pagini recente » Cod sursa (job #2551125) | Cod sursa (job #413671) | Cod sursa (job #2252059) | Cod sursa (job #322411) | Cod sursa (job #2705361)
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
ifstream fin("cmap.in");
ofstream fout("cmap.out");
vector< pair<int,int> > Punct;
double dist(pair<int, int> X, pair<int, int> Y)
{
return sqrt((Y.first-X.first)*(Y.first-X.first)+(Y.second-X.second)*(Y.second-X.second));
}
double Distanta(vector< pair<int, int> > Punct, int st, int dr)
{
double D=0,d1=0,d2=0,d3=0;
if(dr-st==2)
{
d1=dist(Punct[st],Punct[st+1]);
d2=dist(Punct[st+1],Punct[st+2]);
d3=dist(Punct[st],Punct[st+2]);
D=min(d1,min(d2,d3));
}
else if(dr-st==1)
D=dist(Punct[st],Punct[st+1]);
else
{
int mij=(st+dr)/2;
D=min(Distanta(Punct,st,mij),Distanta(Punct,mij+1,dr));
}
return D;
}
int n;
int main()
{
fin >> n;
Punct.resize(n);
for(int i=0;i<n;i++)
fin >> Punct[i].first >> Punct[i].second;
sort(Punct.begin(),Punct.end());
fout << fixed << setprecision(6) << Distanta(Punct,0,n-1);
return 0;
}