标签:des style class blog c code
2 0 0 1 1 2 1 1 1 1 3 -1.5 0 0 0 0 1.5 0
0.71 0.00 0.75
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
struct point{
double x,y;
point(double x,double y):x(x),y(y){}
};
int n;
vector<point> vp,tmp;
bool cmpx(point a,point b){
return a.x < b.x;
}
bool cmpy(point a,point b){
return a.y < b.y;
}
double getDis(point a,point b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double NearestPoint(int sta,int ed){
if(sta+1==ed){
return getDis(vp[sta],vp[ed]);
}
if(sta+2==ed){
return min(min(getDis(vp[sta],vp[sta+1]),getDis(vp[sta+1],vp[ed])),getDis(vp[sta],vp[ed]));
}
int mid = (sta+ed)>>1;
double res = min(NearestPoint(sta,mid),NearestPoint(mid+1,ed));
tmp.clear();
for(int i = sta;i <= ed; i++){
if(fabs(vp[i].x-vp[mid].x)<res){
tmp.push_back(vp[i]);
}
}
sort(tmp.begin(),tmp.end(),cmpy);
for(int i = 0; i < tmp.size(); i++){
for(int j = i+1; j < tmp.size() && tmp[j].y-tmp[i].y<=res; j++){
if(getDis(tmp[i],tmp[j]) < res)
res = getDis(tmp[i],tmp[j]);
}
}
return res;
}
int main(){
while(cin >> n && n){
vp.clear();
for(int i = 0; i < n; i++){
double a,b;
scanf("%lf%lf",&a,&b);
vp.push_back(point(a,b));
}
sort(vp.begin(),vp.end(),cmpx);
printf("%.2f\n",NearestPoint(0,vp.size()-1)/2);
}
return 0;
}
HDU-1007-Quoit Design,布布扣,bubuko.com
标签:des style class blog c code
原文地址:http://blog.csdn.net/mowayao/article/details/26939227