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

Airport UVA - 11168

时间:2017-09-26 23:31:49      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:target   .net   min   ons   name   close   struct   port   cas   

Airport

 UVA - 11168

 

技术分享
 1 #include <bits/stdc++.h>
 2 using  namespace std;
 3 const int maxn = 10010;
 4 const int inf = 0x3f3f3f3f;
 5 const int eps = 1e-12;
 6 
 7 struct Point {
 8     double x, y;
 9     Point (double x = 0, double y = 0) : x(x), y(y) {}
10 };
11 typedef Point Vector;
12 Vector operator - (Point a, Point b) {
13     return Vector(a.x - b.x, a.y - b.y);
14 }
15 bool operator < (Point a, Point b) {
16     return a.x < b.x || (a.x == b.x && a.y < b.y);
17 }
18 int dcmp(double x) {
19     if(fabs(x) < eps) return 0;
20     return x < 0 ? -1 : 1;
21 }
22 double Cross(Vector a, Vector b) {
23     return a.x * b.y - a.y * b.x;
24 }
25 
26 int ConvexHull(Point *p, int n, Point *ch) {
27     sort(p, p+n);
28     int m = 0;
29     for(int i = 0; i < n; i++) {
30         while(m > 1 && Cross(ch[m-1] - ch[m-2], p[i] - ch[m-2]) <= 0) m--;
31         ch[m++] = p[i];
32     }
33     int k = m;
34     for(int i = n-2; i >= 0; i--) {
35         while(m > k && Cross(ch[m-1] - ch[m-2], p[i] - ch[m-2]) <= 0) m--;
36         ch[m++] = p[i];
37     }
38     if(m > 1) m--;
39     return m;
40 }
41 Point p[maxn], ch[maxn];
42 int n;
43 double sumx, sumy;
44 int main(){
45     int t;
46     int kase = 0;
47     //freopen("in.txt", "r", stdin);
48     scanf("%d", &t);
49     while(t--) {
50         scanf("%d", &n);
51         sumx = sumy = 0;
52         for(int i = 0; i < n; i++){
53            scanf("%lf %lf", &p[i].x, &p[i].y); 
54            sumx += p[i].x;
55            sumy += p[i].y;
56         }
57         sumx /= n;
58         sumy /= n;
59         int m = ConvexHull(p, n, ch);
60         ch[m] = ch[0];
61         double ans = 1e15+10;
62         for(int i = 0; i < m; i++) {
63             Point r = ch[i];
64             Vector v = ch[i] - ch[i+1];
65             double a = v.y, b = -v.x, c = v.x * r.y - v.y * r.x;
66             double temp = fabs(a * sumx + b * sumy + c) / sqrt(a*a + b*b);
67             ans = min(ans, temp);
68         }
69         printf("Case #%d: %.3lf\n", ++kase, n>2 ? ans : 0);
70     }
71     return 0;
72 }
View Code

 

Airport UVA - 11168

标签:target   .net   min   ons   name   close   struct   port   cas   

原文地址:http://www.cnblogs.com/yijiull/p/7599398.html

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