【HDOJ】1007 Quoit Design

简单数学题,wa的不明所以,ac的也不明所以。

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <math.h>
 4 
 5 #define MAXNUM 100005
 6 #define MAXN   999999999
 7 
 8 typedef struct {
 9     double x, y;
10 } point_st;
11 
12 point_st points[MAXNUM];
13 
14 int comp(const void *a, const void *b) {
15     if ( ((point_st *)a)->y == ((point_st *)b)->y )
16         return ((point_st *)a)->x < ((point_st *)b)->x ? 1:-1;
17     else
18         return ((point_st *)a)->y < ((point_st *)b)->y ? 1:-1;
19 }
20 
21 int comp1(const void *a, const void *b) {
22     if ( ((point_st *)a)->x == ((point_st *)b)->x )
23         return ((point_st *)a)->y < ((point_st *)b)->y ? 1:-1;
24     else
25         return ((point_st *)a)->x < ((point_st *)b)->x ? 1:-1;
26 }
27 
28 int main() {
29     int n;
30     int i;
31     double tmp, min;
32 
33     while (scanf("%d", &n)!=EOF && n) {
34         for (i=0; i<n; ++i)
35             scanf("%lf%lf", &points[i].x, &points[i].y);
36         qsort(points, n, sizeof(point_st), comp);
37         min = MAXN;
38         for (i=1; i<n; ++i) {
39             tmp = pow(points[i].x-points[i-1].x, 2) + pow(points[i].y-points[i-1].y, 2);
40             tmp = sqrt(tmp) / 2.0f;
41             if (tmp < min)
42                 min = tmp;
43         }
44         qsort(points, n, sizeof(point_st), comp1);
45         for (i=1; i<n; ++i) {
46             tmp = pow(points[i].x-points[i-1].x, 2) + pow(points[i].y-points[i-1].y, 2);
47             tmp = sqrt(tmp) / 2.0f;
48             if (tmp < min)
49                 min = tmp;
50         }
51         printf("%.2lf\n", min);
52     }
53 
54     return 0;
55 }

 

posted on 2014-04-03 09:50  Bombe  阅读(163)  评论(0编辑  收藏  举报

导航