首页 > 代码库 > hdu_1007
hdu_1007
1 // hdu 1007 2 // 3 // Dec.29 2014 4 5 #include <cstdio> 6 #include <cmath> 7 #include <algorithm> 8 9 #define MaxN 11111110 11 struct point12 {13 double x, y;14 }p[MaxN];15 16 int n;17 18 bool cmp1(point p1, point p2){19 return p1.x < p2.x;20 }21 bool cmp2(point p1, point p2){22 return p1.y < p2.y;23 }24 25 int main(int argc, char const *argv[])26 {27 // freopen("in", "r", stdin);28 while(scanf("%d",&n) && n){29 for (int i = 0; i < n; ++i)30 scanf("%lf%lf",&p[i].x, &p[i].y);31 // first sort, ordered by 32 std::sort(p, p+n, cmp1);33 double min_radio = 111111111;34 for (int i = 1; i < n; ++i){35 // double temp = hypot(p[i].x - p[i-1].x, p[i].y - p[i-1].y);36 double temp = sqrt( (p[i].x - p[i-1].x)*(p[i].x - p[i-1].x) + (p[i].y - p[i-1].y)*(p[i].y - p[i-1].y) );37 if(min_radio > temp )38 min_radio = temp;39 }40 // second sort, ordered by py increased.41 std::sort(p, p+n, cmp2);42 for (int i = 1; i < n; ++i){43 // double temp = hypot(p[i].x - p[i-1].x, p[i].y - p[i-1].y);44 double temp = sqrt( (p[i].x - p[i-1].x)*(p[i].x - p[i-1].x) + (p[i].y - p[i-1].y)*(p[i].y - p[i-1].y) ); 45 if(min_radio > temp )46 min_radio = temp;47 }48 printf("%.2lf\n", min_radio/2);49 }50 return 0;51 }
hdu_1007
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。