uva 11168 - Airport

时间:2023-12-22 19:52:02

凸包+一点直线的知识;

 #include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#define eps 1e-9
using namespace std;
const double pi = acos(-); int dcmp(double x)
{
return fabs(x) < eps ? : (x > ? : -);
} struct Point
{
double x;
double y; Point(double x = , double y = ):x(x), y(y) {} bool operator < (const Point& e) const
{
return dcmp(x - e.x) < || (dcmp(x - e.x) == && dcmp(y - e.y) < );
} bool operator == (const Point& e) const
{
return dcmp(x - e.x) == && dcmp(y - e.y) == ;
}
}; typedef Point Vector; Vector operator + (Point A, Point B)
{
return Vector(A.x + B.x, A.y + B.y);
} Vector operator - (Point A, Point B)
{
return Vector(A.x - B.x, A.y - B.y);
} Vector operator * (Point A, double p)
{
return Vector(A.x * p, A.y * p);
} Vector operator / (Point A, double p)
{
return Vector(A.x / p, A.y / p);
} double cross(Point a,Point b){return a.x*b.y-a.y*b.x;}
Point rotate(Point a,double ang){return Point(a.x*cos(ang)-a.y*sin(ang),a.x*sin(ang)+a.y*cos(ang));}
int convexhull(Point *p,int n,Point *ch)
{
sort(p,p+n);
int m=;
for(int i=;i<n;i++)
{
while(m>&&cross(ch[m-]-ch[m-],p[i]-ch[m-])<=)m--;
ch[m++]=p[i];
}
int k=m;
for(int i=n-;i>=;i--)
{
while(m>k&&cross(ch[m-]-ch[m-],p[i]-ch[m-])<=)m--;
ch[m++]=p[i];
}
if(n>)m--;
return m;
}
Point p[],ch[]; int main()
{
int t,n,ca=;
scanf("%d",&t);
while(t--)
{
double sumx=;
double sumy=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
sumx+=p[i].x;
sumy+=p[i].y;
}
printf("Case #%d: ",ca++);
double mi=99999999999.0;
int m=convexhull(p,n,ch);
for(int i=;i<m;i++)
{
double a=-ch[(i+)%m].y+ch[i].y;
double b=ch[(i+)%m].x-ch[i].x;
double c=ch[i].x*ch[(i+)%m].y-ch[i].y*ch[(i+)%m].x;
double d=fabs(a*sumx+b*sumy+c*n)/sqrt(a*a+b*b);
mi=min(mi,d);
}
printf("%.3lf\n",n>?mi/n:);
}
return ;
}