hdu_1007

 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 }
时间: 2024-10-13 22:25:52

hdu_1007的相关文章