码迷,mamicode.com
首页 > 其他好文 > 详细

hdu_1007

时间:2015-01-02 17:27:40      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

 1 // hdu 1007
 2 // 
 3 // Dec.29 2014
 4 
 5 #include <cstdio>
 6 #include <cmath>
 7 #include <algorithm>
 8 
 9 #define MaxN 111111
10 
11 struct point
12 {
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

标签:

原文地址:http://www.cnblogs.com/takeoffyoung/p/4198558.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!