Airport UVA - 11168
Posted yijiull
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Airport UVA - 11168相关的知识,希望对你有一定的参考价值。
Airport
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 }
以上是关于Airport UVA - 11168的主要内容,如果未能解决你的问题,请参考以下文章