几何算法专题

  • UVA 10652 Board Wrapping
  • UVA 11168 Airport
  • UVA 1396 Most Distant Point from the Sea
  • UVA 1298 Triathlon
  • UVA 1475 Jungle Outpost

UVA 10652 Board Wrapping

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch==‘-‘) f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-‘0‘; ch=getchar();}
    return x*f;
}
ll sqr(ll a){return a*a;}
ld sqr(ld a){return a*a;}
double sqr(double a){return a*a;}

ld PI = 3.141592653589793238462643383;
class P{
public:
    double x,y;
    P(double x=0,double y=0):x(x),y(y){}
    friend long double dis2(P A,P B){return sqr(A.x-B.x)+sqr(A.y-B.y);  }
    friend long double Dot(P A,P B) {return A.x*B.x+A.y*B.y; }
    friend long double Length(P A) {return sqrt(Dot(A,A)); }
    friend long double Angle(P A,P B) {return acos(Dot(A,B) / Length(A) / Length(B) ); }

    friend P operator- (P A,P B) { return P(A.x-B.x,A.y-B.y); }
    friend P operator+ (P A,P B) { return P(A.x+B.x,A.y+B.y); }
    friend P operator* (P A,double p) { return P(A.x*p,A.y*p); }
    friend P operator/ (P A,double p) { return P(A.x/p,A.y/p); }
    friend bool operator< (const P& a,const P& b) {return a.x<b.x||(a.x==b.x&& a.y<b.y);}

};
const double eps=1e-10;
int dcmp(double x) {
    if (fabs(x)<eps) return 0; else return x<0 ? -1 : 1;
}
bool operator==(const P& a,const P& b) {
    return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y) == 0;
}
typedef P V;

double Cross(V A,V B) {return A.x*B.y - A.y*B.x;}
double Area2(P A,P B,P C) {return Cross(B-A,C-A);}
//rad 是弧度 逆时针旋转
V Rotate(V A,double rad) {
    return V(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
// A 不是 0向量
V Normal(V A) {
    double L = Length(A);
    return V(-A.y/L , A.x/L);
}

namespace complex_G{
    typedef complex<double> Point;
    //real(p):实部 imag(p):虚部 conj(p):共轭
    typedef Point Vector;
    double Dot(Vector A,Vector B) {return real(conj(A)*B); }
    double Cross(Vector A,Vector B) {return imag(conj(A)*B); }
    Vector Rotate(Vector A,double rad) {return A*exp(Point(0,rad)); }
}
//Cross(v,w)==0(平行)时,不能调这个函数
P GetLineIntersection(P p,V v,P Q,V w){
    V u = p-Q;
    double t = Cross(w,u)/Cross(v,w);
    return p+v*t;
}
P GetLineIntersectionB(P p,V v,P Q,V w){
    return GetLineIntersection(p,v-p,Q,w-Q);
}

double DistanceToLine(P p,P A,P B) {
    V v1 = B-A, v2 = p-A;
    return fabs(Cross(v1,v2))/Length(v1);
}
double DistanceToSegment(P p,P A,P B) {
    if (A==B) return Length(p-A);
    V v1 = B-A, v2 = p-A, v3 = p - B;
    if (dcmp(Dot(v1,v2))<0) return Length(v2);
    else if (dcmp(Dot(v1,v3))>0 ) return Length(v3);
    else return fabs(Cross(v1,v2) ) / Length(v1);
}
P GetLineProjection(P p,P A,P B) {
    V v=B-A;
    return A+v*(Dot(v,p-A)/Dot(v,v));
}
//规范相交-线段相交且交点不在端点
bool SegmentProperIntersection(P a1,P a2,P b1,P b2) {
    double  c1 = Cross(a2-a1,b1-a1) , c2 = Cross(a2-a1,b2-a1),
            c3 = Cross(b2-b1,a1-b1) , c4 = Cross(b2-b1,a2-b1);
    return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0;
}
//点在线段上(不包含端点)
bool OnSegment(P p,P a1,P a2) {
    return dcmp(Cross(a1-p,a2-p)) == 0 && dcmp(Dot(a1-p,a2-p))<0;
}
double PolygonArea(P *p,int n) {
    double area=0;
    For(i,n-2) area+=Cross(p[i]-p[0],p[i+1]-p[0]);
    return area/2;
}
/*欧拉公式: V+F-E=2
V-点数 F面数 E边数 */
P read_point() {
    P a;
    scanf("%lf%lf",&a.x,&a.y);
    return a;
}
struct C{
    P c;
    double r,x,y;
    C(P c,double r):c(c),r(r),x(c.x),y(c.y){}
    P point(double a) {
        return P(c.x+cos(a)*r,c.y+sin(a)*r);
    }
};

struct Line{
    P p;
    V v;
    double ang;
    Line(){}
    Line(P p,V v):p(p),v(v) {ang=atan2(v.y,v.x); }
    bool operator<(const Line & L) const {
        return ang<L.ang;
    }
    P point(double a) {
        return p+v*a;
    }
};
int getLineCircleIntersection(Line L,C cir,double &t1,double &t2,vector<P> & sol) {
    if (dcmp(DistanceToLine(cir.c,L.p,L.p+L.v)-cir.r)==0) {
        sol.pb(GetLineProjection(cir.c,L.p,L.p+L.v));
        return 1;
    }

    double a = L.v.x, b = L.p.x - cir.c.x, c = L.v.y, d= L.p.y - cir.c.y;
    double e = a*a+c*c, f = 2*(a*b + c*d), g = b*b+d*d-cir.r*cir.r;
    double delta = f*f - 4*e*g;
    if (dcmp(delta)<0) return 0;
    else if (dcmp(delta)==0) {
        t1 = t2 = -f / (2*e); sol.pb(L.point(t1));
        return 1;
    }
    t1 = (-f - sqrt(delta)) / (2*e); sol.pb(L.point(t1));
    t2 = (-f + sqrt(delta)) / (2*e); sol.pb(L.point(t2));
    return 2;
}
double angle(V v) {return atan2(v.y,v.x);}
int getCircleCircleIntersection(C C1,C C2,vector<P>& sol) {
    double d = Length(C1.c-C2.c);
    if (dcmp(d)==0) {
        if (dcmp(C1.r - C2.r)==0) return -1; //2圆重合
        return 0;
    }
    if (dcmp(C1.r+C2.r-d)<0) return 0;
    if (dcmp(fabs(C1.r-C2.r)-d)>0) return 0;

    double a = angle(C2.c-C1.c);
    double da = acos((C1.r*C1.r+d*d - C2.r*C2.r)/ (2*C1.r*d));
    P p1 = C1.point(a-da), p2 = C1.point(a+da);
    sol.pb(p1);
    if (p1==p2) return 1;
    sol.pb(p2);
    return 2;
}
// Tangents-切线
int getTangents(P p,C c,V* v) {
    V u= c.c-p;
    double dist = Length(u);
    if (dist<c.r) return 0;
    else if (dcmp(dist-c.r)==0) {
        v[0]=Rotate(u,PI/2);
        return 1;
    } else {
        double ang = asin(c.r / dist);
        v[0]=Rotate(u,-ang);
        v[1]=Rotate(u,ang);
        return 2;
    }
}
//这个函数假设整数坐标和整数半径
//double时要把int改成double
int getTangents(C A,C B,P* a,P* b) {
    int cnt=0;
    if (A.r<B.r) {swap(A,B),swap(a,b);}
    int d2 = (A.c.x-B.c.x)*(A.c.x-B.c.x) + (A.c.y-B.c.y)*(A.c.y-B.c.y);
    int rdiff = A.r-B.r;
    int rsum = A.r+B.r;
    if (d2<rdiff*rdiff) return 0;
    double base = atan2(B.y-A.y,B.x-A.x);
    if (d2==0 && A.r == B.r) return -1;
    if (d2 == rdiff*rdiff) {
        a[cnt] = A.point(base); b[cnt] = B.point(base); ++cnt;
        return 1;
    }
    double ang = acos((A.r-B.r)/sqrt(d2));
    a[cnt] = A.point(base+ang); b[cnt] = B.point(base+ang); ++cnt;
    a[cnt] = A.point(base-ang); b[cnt] = B.point(base-ang); ++cnt;
    if (d2==rsum*rsum) {
        a[cnt] = A.point(base); b[cnt] = B.point(PI+base); ++cnt;
    }
    else if (d2>rsum*rsum) {
        double ang = acos((A.r+B.r)/sqrt(d2));
        a[cnt] = A.point(base+ang); b[cnt] = B.point(PI+base+ang); ++cnt;
        a[cnt] = A.point(base-ang); b[cnt] = B.point(PI+base-ang); ++cnt;
    }
    return cnt;
}
//Circumscribed-外接
C CircumscribedCircle(P p1,P p2,P p3) {
    double Bx = p2.x-p1.x, By= p2.y-p1.y;
    double Cx = p3.x-p1.x, Cy= p3.y-p1.y;
    double D = 2*(Bx*Cy-By*Cx);
    double cx = (Cy*(Bx*Bx+By*By)-By*(Cx*Cx+Cy*Cy))/D + p1.x;
    double cy = (Bx*(Cx*Cx+Cy*Cy)-Cx*(Bx*Bx+By*By))/D + p1.y;
    P p =P(cx,cy);
    return C(p,Length(p1-p));
}
//Inscribed-内接
C InscribedCircle(P p1,P p2,P p3) {
    double a = Length(p2-p3);
    double b = Length(p3-p1);
    double c = Length(p1-p2);
    P p = (p1*a+p2*b+p3*c)/(a+b+c);
    return C(p,DistanceToLine(p,p1,p2));
}
double torad(double deg) {
    return deg/180*acos(-1);
}
//把 角度+-pi 转换到 [0,pi) 上
double radToPositive(double rad) {
    if (dcmp(rad)<0) rad=ceil(-rad/PI)*PI+rad;
    if (dcmp(rad-PI)>=0) rad-=floor(rad/PI)*PI;
    return rad;
}
double todeg(double rad) {
    return rad*180/acos(-1);
}

//(R,lat,lng)->(x,y,z)
void get_coord(double R,double lat,double lng,double &x,double &y,double &z) {
    lat=torad(lat);
    lng=torad(lng);
    x=R*cos(lat)*cos(lng);
    y=R*cos(lat)*sin(lng);
    z=R*sin(lat);
}
void print(double a) {
    printf("%.6lf",a);
}
void print(P p) {
    printf("(%.6lf,%.6lf)",p.x,p.y);
}
template<class T>
void print(vector<T> v) {
    sort(v.begin(),v.end());
    putchar(‘[‘);
    int n=v.size();
    Rep(i,n) {
        print(v[i]);
        if (i<n-1) putchar(‘,‘);
    }
    puts("]");
}
// 把直线沿v平移
// Translation-平移
Line LineTranslation(Line l,V v) {
    l.p=l.p+v;
    return l;
}
void CircleThroughAPointAndTangentToALineWithRadius(P p,Line l,double r,vector<P>& sol) {
    V e=Normal(l.v);
    Line l1=LineTranslation(l,e*r),l2=LineTranslation(l,e*(-r));
    double t1,t2;
    getLineCircleIntersection(l1,C(p,r),t1,t2,sol);
    getLineCircleIntersection(l2,C(p,r),t1,t2,sol);
}
void CircleTangentToTwoLinesWithRadius(Line l1,Line l2,double r,vector<P>& sol) {
    V e1=Normal(l1.v),e2=Normal(l2.v);
    Line L1[2]={LineTranslation(l1,e1*r),LineTranslation(l1,e1*(-r))},
         L2[2]={LineTranslation(l2,e2*r),LineTranslation(l2,e2*(-r))};
    Rep(i,2) Rep(j,2) sol.pb(GetLineIntersection(L1[i].p,L1[i].v,L2[j].p,L2[j].v));
}
void CircleTangentToTwoDisjointCirclesWithRadius(C c1,C c2,double r,vector<P>& sol) {
    c1.r+=r; c2.r+=r;
    getCircleCircleIntersection(c1,c2,sol);
}
//确定4个点能否组成凸多边形,并按顺序(不一定是逆时针)返回
bool ConvexPolygon(P &A,P &B,P &C,P &D) {
    if (SegmentProperIntersection(A,C,B,D)) return 1;
    swap(B,C);
    if (SegmentProperIntersection(A,C,B,D)) return 1;
    swap(D,C);
    if (SegmentProperIntersection(A,C,B,D)) return 1;
    return 0;
}
bool IsParallel(P A,P B,P C,P D) {
    return dcmp(Cross(B-A,D-C))==0;
}
bool IsPerpendicular(V A,V B) {
    return dcmp(Dot(A,B))==0;
}
//先调用ConvexPolygon 求凸包并确认是否是四边形
// Trapezium-梯形 Rhombus-菱形
bool IsTrapezium(P A,P B,P C,P D){
    return IsParallel(A,B,C,D)^IsParallel(B,C,A,D);
}
bool IsParallelogram(P A,P B,P C,P D) {
    return IsParallel(A,B,C,D)&&IsParallel(B,C,A,D);
}
bool IsRhombus(P A,P B,P C,P D) {
    return IsParallelogram(A,B,C,D)&&dcmp(Length(B-A)-Length(C-B))==0;
}
bool IsRectangle(P A,P B,P C,P D) {
    return IsParallelogram(A,B,C,D)&&IsPerpendicular(B-A,D-A);
}
bool IsSquare(P A,P B,P C,P D) {
    return IsParallelogram(A,B,C,D)&&IsPerpendicular(B-A,D-A)&&dcmp(Length(B-A)-Length(C-B))==0;
}

//chord-弦 arc-弧
double ArcDis(double chord,double r) {
    return 2*asin(chord/2/r)*r;
}
typedef vector<P> Polygon ;
int isPointInPolygon(P p,Polygon poly) {
    int wn=0;
    int n=poly.size();
    Rep(i,n) {
        if (OnSegment(p,poly[i],poly[(i+1)%n])) return -1;
        int k=dcmp(Cross(poly[(i+1)%n]-poly[i],p-poly[i]));
        int d1 = dcmp(poly[i].y-p.y);
        int d2 = dcmp(poly[(i+1)%n].y-p.y);
        if ( k > 0 && d1 <= 0 && d2 > 0 ) wn++;
        if ( k < 0 && d2 <= 0 && d1 > 0 ) wn--;
    }
    if (wn!=0) return 1;
    return 0;
}

int ConvexHull(P *p,int n,P *ch) {
    sort(p,p+n);
    int m=0;
    Rep(i,n) {
        while(m>1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
        ch[m++]=p[i];
    }
    int k=m;
    RepD(i,n-2) {
        while(m>k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
        ch[m++]=p[i];
    }
    if ( n > 1 ) m--;
    return m;
}

#define MAXN (2500)
P p[MAXN],ch[MAXN];
int main()
{
//  freopen("uva10652.in","r",stdin);
//  freopen(".out","w",stdout);

    int T=read();
    while(T--) {
        int n=read(),pc=0;
        double area1=0;
        Rep(i,n) {
            double x,y,w,h,j;
            cin>>x>>y>>w>>h>>j;
            j=-torad(j);
            P o(x,y);
            area1+=w*h;
            p[pc++]= o + Rotate(V(w/2,h/2),j);
            p[pc++]= o + Rotate(V(-w/2,h/2),j);
            p[pc++]= o + Rotate(V(w/2,-h/2),j);
            p[pc++]= o + Rotate(V(-w/2,-h/2),j);

        }
        int m=ConvexHull(p,pc,ch);
        double area2 = PolygonArea(ch,m);
        printf("%.1lf %%\n",area1*100/area2);
    }

    return 0;
}

UVA 11168 Airport

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch==‘-‘) f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-‘0‘; ch=getchar();}
    return x*f;
}
ll sqr(ll a){return a*a;}
ld sqr(ld a){return a*a;}
double sqr(double a){return a*a;}

ld PI = 3.141592653589793238462643383;
class P{
public:
    double x,y;
    P(double x=0,double y=0):x(x),y(y){}
    friend long double dis2(P A,P B){return sqr(A.x-B.x)+sqr(A.y-B.y);  }
    friend long double Dot(P A,P B) {return A.x*B.x+A.y*B.y; }
    friend long double Length(P A) {return sqrt(Dot(A,A)); }
    friend long double Angle(P A,P B) {return acos(Dot(A,B) / Length(A) / Length(B) ); }

    friend P operator- (P A,P B) { return P(A.x-B.x,A.y-B.y); }
    friend P operator+ (P A,P B) { return P(A.x+B.x,A.y+B.y); }
    friend P operator* (P A,double p) { return P(A.x*p,A.y*p); }
    friend P operator/ (P A,double p) { return P(A.x/p,A.y/p); }
    friend bool operator< (const P& a,const P& b) {return a.x<b.x||(a.x==b.x&& a.y<b.y);}

};
const double eps=1e-10;
int dcmp(double x) {
    if (fabs(x)<eps) return 0; else return x<0 ? -1 : 1;
}
bool operator==(const P& a,const P& b) {
    return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y) == 0;
}
typedef P V;

double Cross(V A,V B) {return A.x*B.y - A.y*B.x;}
double Area2(P A,P B,P C) {return Cross(B-A,C-A);}
//rad 是弧度 逆时针旋转
V Rotate(V A,double rad) {
    return V(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
// A 不是 0向量
V Normal(V A) {
    double L = Length(A);
    return V(-A.y/L , A.x/L);
}

namespace complex_G{
    typedef complex<double> Point;
    //real(p):实部 imag(p):虚部 conj(p):共轭
    typedef Point Vector;
    double Dot(Vector A,Vector B) {return real(conj(A)*B); }
    double Cross(Vector A,Vector B) {return imag(conj(A)*B); }
    Vector Rotate(Vector A,double rad) {return A*exp(Point(0,rad)); }
}
//Cross(v,w)==0(平行)时,不能调这个函数
P GetLineIntersection(P p,V v,P Q,V w){
    V u = p-Q;
    double t = Cross(w,u)/Cross(v,w);
    return p+v*t;
}
P GetLineIntersectionB(P p,V v,P Q,V w){
    return GetLineIntersection(p,v-p,Q,w-Q);
}

double DistanceToLine(P p,P A,P B) {
    V v1 = B-A, v2 = p-A;
    return fabs(Cross(v1,v2))/Length(v1);
}
double DistanceToSegment(P p,P A,P B) {
    if (A==B) return Length(p-A);
    V v1 = B-A, v2 = p-A, v3 = p - B;
    if (dcmp(Dot(v1,v2))<0) return Length(v2);
    else if (dcmp(Dot(v1,v3))>0 ) return Length(v3);
    else return fabs(Cross(v1,v2) ) / Length(v1);
}
P GetLineProjection(P p,P A,P B) {
    V v=B-A;
    return A+v*(Dot(v,p-A)/Dot(v,v));
}
//规范相交-线段相交且交点不在端点
bool SegmentProperIntersection(P a1,P a2,P b1,P b2) {
    double  c1 = Cross(a2-a1,b1-a1) , c2 = Cross(a2-a1,b2-a1),
            c3 = Cross(b2-b1,a1-b1) , c4 = Cross(b2-b1,a2-b1);
    return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0;
}
//点在线段上(不包含端点)
bool OnSegment(P p,P a1,P a2) {
    return dcmp(Cross(a1-p,a2-p)) == 0 && dcmp(Dot(a1-p,a2-p))<0;
}
double PolygonArea(P *p,int n) {
    double area=0;
    For(i,n-2) area+=Cross(p[i]-p[0],p[i+1]-p[0]);
    return area/2;
}
/*欧拉公式: V+F-E=2
V-点数 F面数 E边数 */
P read_point() {
    P a;
    scanf("%lf%lf",&a.x,&a.y);
    return a;
}
struct C{
    P c;
    double r,x,y;
    C(P c,double r):c(c),r(r),x(c.x),y(c.y){}
    P point(double a) {
        return P(c.x+cos(a)*r,c.y+sin(a)*r);
    }
};

struct Line{
    P p;
    V v;
    double ang;
    Line(){}
    Line(P p,V v):p(p),v(v) {ang=atan2(v.y,v.x); }
    bool operator<(const Line & L) const {
        return ang<L.ang;
    }
    P point(double a) {
        return p+v*a;
    }
};
int getLineCircleIntersection(Line L,C cir,double &t1,double &t2,vector<P> & sol) {
    if (dcmp(DistanceToLine(cir.c,L.p,L.p+L.v)-cir.r)==0) {
        sol.pb(GetLineProjection(cir.c,L.p,L.p+L.v));
        return 1;
    }

    double a = L.v.x, b = L.p.x - cir.c.x, c = L.v.y, d= L.p.y - cir.c.y;
    double e = a*a+c*c, f = 2*(a*b + c*d), g = b*b+d*d-cir.r*cir.r;
    double delta = f*f - 4*e*g;
    if (dcmp(delta)<0) return 0;
    else if (dcmp(delta)==0) {
        t1 = t2 = -f / (2*e); sol.pb(L.point(t1));
        return 1;
    }
    t1 = (-f - sqrt(delta)) / (2*e); sol.pb(L.point(t1));
    t2 = (-f + sqrt(delta)) / (2*e); sol.pb(L.point(t2));
    return 2;
}
double angle(V v) {return atan2(v.y,v.x);}
int getCircleCircleIntersection(C C1,C C2,vector<P>& sol) {
    double d = Length(C1.c-C2.c);
    if (dcmp(d)==0) {
        if (dcmp(C1.r - C2.r)==0) return -1; //2圆重合
        return 0;
    }
    if (dcmp(C1.r+C2.r-d)<0) return 0;
    if (dcmp(fabs(C1.r-C2.r)-d)>0) return 0;

    double a = angle(C2.c-C1.c);
    double da = acos((C1.r*C1.r+d*d - C2.r*C2.r)/ (2*C1.r*d));
    P p1 = C1.point(a-da), p2 = C1.point(a+da);
    sol.pb(p1);
    if (p1==p2) return 1;
    sol.pb(p2);
    return 2;
}
// Tangents-切线
int getTangents(P p,C c,V* v) {
    V u= c.c-p;
    double dist = Length(u);
    if (dist<c.r) return 0;
    else if (dcmp(dist-c.r)==0) {
        v[0]=Rotate(u,PI/2);
        return 1;
    } else {
        double ang = asin(c.r / dist);
        v[0]=Rotate(u,-ang);
        v[1]=Rotate(u,ang);
        return 2;
    }
}
//这个函数假设整数坐标和整数半径
//double时要把int改成double
int getTangents(C A,C B,P* a,P* b) {
    int cnt=0;
    if (A.r<B.r) {swap(A,B),swap(a,b);}
    int d2 = (A.c.x-B.c.x)*(A.c.x-B.c.x) + (A.c.y-B.c.y)*(A.c.y-B.c.y);
    int rdiff = A.r-B.r;
    int rsum = A.r+B.r;
    if (d2<rdiff*rdiff) return 0;
    double base = atan2(B.y-A.y,B.x-A.x);
    if (d2==0 && A.r == B.r) return -1;
    if (d2 == rdiff*rdiff) {
        a[cnt] = A.point(base); b[cnt] = B.point(base); ++cnt;
        return 1;
    }
    double ang = acos((A.r-B.r)/sqrt(d2));
    a[cnt] = A.point(base+ang); b[cnt] = B.point(base+ang); ++cnt;
    a[cnt] = A.point(base-ang); b[cnt] = B.point(base-ang); ++cnt;
    if (d2==rsum*rsum) {
        a[cnt] = A.point(base); b[cnt] = B.point(PI+base); ++cnt;
    }
    else if (d2>rsum*rsum) {
        double ang = acos((A.r+B.r)/sqrt(d2));
        a[cnt] = A.point(base+ang); b[cnt] = B.point(PI+base+ang); ++cnt;
        a[cnt] = A.point(base-ang); b[cnt] = B.point(PI+base-ang); ++cnt;
    }
    return cnt;
}
//Circumscribed-外接
C CircumscribedCircle(P p1,P p2,P p3) {
    double Bx = p2.x-p1.x, By= p2.y-p1.y;
    double Cx = p3.x-p1.x, Cy= p3.y-p1.y;
    double D = 2*(Bx*Cy-By*Cx);
    double cx = (Cy*(Bx*Bx+By*By)-By*(Cx*Cx+Cy*Cy))/D + p1.x;
    double cy = (Bx*(Cx*Cx+Cy*Cy)-Cx*(Bx*Bx+By*By))/D + p1.y;
    P p =P(cx,cy);
    return C(p,Length(p1-p));
}
//Inscribed-内接
C InscribedCircle(P p1,P p2,P p3) {
    double a = Length(p2-p3);
    double b = Length(p3-p1);
    double c = Length(p1-p2);
    P p = (p1*a+p2*b+p3*c)/(a+b+c);
    return C(p,DistanceToLine(p,p1,p2));
}
double torad(double deg) {
    return deg/180*acos(-1);
}
//把 角度+-pi 转换到 [0,pi) 上
double radToPositive(double rad) {
    if (dcmp(rad)<0) rad=ceil(-rad/PI)*PI+rad;
    if (dcmp(rad-PI)>=0) rad-=floor(rad/PI)*PI;
    return rad;
}
double todeg(double rad) {
    return rad*180/acos(-1);
}

//(R,lat,lng)->(x,y,z)
void get_coord(double R,double lat,double lng,double &x,double &y,double &z) {
    lat=torad(lat);
    lng=torad(lng);
    x=R*cos(lat)*cos(lng);
    y=R*cos(lat)*sin(lng);
    z=R*sin(lat);
}
void print(double a) {
    printf("%.6lf",a);
}
void print(P p) {
    printf("(%.6lf,%.6lf)",p.x,p.y);
}
template<class T>
void print(vector<T> v) {
    sort(v.begin(),v.end());
    putchar(‘[‘);
    int n=v.size();
    Rep(i,n) {
        print(v[i]);
        if (i<n-1) putchar(‘,‘);
    }
    puts("]");
}
// 把直线沿v平移
// Translation-平移
Line LineTranslation(Line l,V v) {
    l.p=l.p+v;
    return l;
}
void CircleThroughAPointAndTangentToALineWithRadius(P p,Line l,double r,vector<P>& sol) {
    V e=Normal(l.v);
    Line l1=LineTranslation(l,e*r),l2=LineTranslation(l,e*(-r));
    double t1,t2;
    getLineCircleIntersection(l1,C(p,r),t1,t2,sol);
    getLineCircleIntersection(l2,C(p,r),t1,t2,sol);
}
void CircleTangentToTwoLinesWithRadius(Line l1,Line l2,double r,vector<P>& sol) {
    V e1=Normal(l1.v),e2=Normal(l2.v);
    Line L1[2]={LineTranslation(l1,e1*r),LineTranslation(l1,e1*(-r))},
         L2[2]={LineTranslation(l2,e2*r),LineTranslation(l2,e2*(-r))};
    Rep(i,2) Rep(j,2) sol.pb(GetLineIntersection(L1[i].p,L1[i].v,L2[j].p,L2[j].v));
}
void CircleTangentToTwoDisjointCirclesWithRadius(C c1,C c2,double r,vector<P>& sol) {
    c1.r+=r; c2.r+=r;
    getCircleCircleIntersection(c1,c2,sol);
}
//确定4个点能否组成凸多边形,并按顺序(不一定是逆时针)返回
bool ConvexPolygon(P &A,P &B,P &C,P &D) {
    if (SegmentProperIntersection(A,C,B,D)) return 1;
    swap(B,C);
    if (SegmentProperIntersection(A,C,B,D)) return 1;
    swap(D,C);
    if (SegmentProperIntersection(A,C,B,D)) return 1;
    return 0;
}
bool IsParallel(P A,P B,P C,P D) {
    return dcmp(Cross(B-A,D-C))==0;
}
bool IsPerpendicular(V A,V B) {
    return dcmp(Dot(A,B))==0;
}
//先调用ConvexPolygon 求凸包并确认是否是四边形
// Trapezium-梯形 Rhombus-菱形
bool IsTrapezium(P A,P B,P C,P D){
    return IsParallel(A,B,C,D)^IsParallel(B,C,A,D);
}
bool IsParallelogram(P A,P B,P C,P D) {
    return IsParallel(A,B,C,D)&&IsParallel(B,C,A,D);
}
bool IsRhombus(P A,P B,P C,P D) {
    return IsParallelogram(A,B,C,D)&&dcmp(Length(B-A)-Length(C-B))==0;
}
bool IsRectangle(P A,P B,P C,P D) {
    return IsParallelogram(A,B,C,D)&&IsPerpendicular(B-A,D-A);
}
bool IsSquare(P A,P B,P C,P D) {
    return IsParallelogram(A,B,C,D)&&IsPerpendicular(B-A,D-A)&&dcmp(Length(B-A)-Length(C-B))==0;
}

//chord-弦 arc-弧
double ArcDis(double chord,double r) {
    return 2*asin(chord/2/r)*r;
}
typedef vector<P> Polygon ;
int isPointInPolygon(P p,Polygon poly) {
    int wn=0;
    int n=poly.size();
    Rep(i,n) {
        if (OnSegment(p,poly[i],poly[(i+1)%n])) return -1;
        int k=dcmp(Cross(poly[(i+1)%n]-poly[i],p-poly[i]));
        int d1 = dcmp(poly[i].y-p.y);
        int d2 = dcmp(poly[(i+1)%n].y-p.y);
        if ( k > 0 && d1 <= 0 && d2 > 0 ) wn++;
        if ( k < 0 && d2 <= 0 && d1 > 0 ) wn--;
    }
    if (wn!=0) return 1;
    return 0;
}

int ConvexHull(P *p,int n,P *ch) {
    sort(p,p+n);
    int m=0;
    Rep(i,n) {
        while(m>1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
        ch[m++]=p[i];
    }
    int k=m;
    RepD(i,n-2) {
        while(m>k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
        ch[m++]=p[i];
    }
    if ( n > 1 ) m--;
    return m;
}

#define MAXN (10000+10)
P p[MAXN],ch[MAXN];
void calc(P A,P B,double &a,double &b,double &c){
    a = A.y - B.y;
    b = B.x - A.x;
    c = Cross(A,B);
}
int main()
{
//  freopen("uva11168.in","r",stdin);
//  freopen(".out","w",stdout);

    int T=read();
    For(kcase,T) {
        int n=read();
        double sx=0,sy=0;
        Rep(i,n) {
            p[i]=read_point();
            sx+=p[i].x; sy+=p[i].y;
        }
        int m=ConvexHull(p,n,ch);
        double ans=0;
        Rep(i,m) {
            double a,b,c;
            calc(ch[i],ch[(i+1)%m],a,b,c);
            double d = fabs(a*sx+b*sy+c*n) / sqrt(a*a + b*b);
            if (!i) ans=d;
            ans=min(ans,d);
        }
        if (n<=2) ans=0;
        printf("Case #%d: %.3lf\n",kcase,ans/n);

    }

    return 0;
}

UVA 1396 Most Distant Point from the Sea

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch==‘-‘) f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-‘0‘; ch=getchar();}
    return x*f;
}
ll sqr(ll a){return a*a;}
ld sqr(ld a){return a*a;}
double sqr(double a){return a*a;}

ld PI = 3.141592653589793238462643383;
class P{
public:
    double x,y;
    P(double x=0,double y=0):x(x),y(y){}
    friend long double dis2(P A,P B){return sqr(A.x-B.x)+sqr(A.y-B.y);  }
    friend long double Dot(P A,P B) {return A.x*B.x+A.y*B.y; }
    friend long double Length(P A) {return sqrt(Dot(A,A)); }
    friend long double Angle(P A,P B) {return acos(Dot(A,B) / Length(A) / Length(B) ); }

    friend P operator- (P A,P B) { return P(A.x-B.x,A.y-B.y); }
    friend P operator+ (P A,P B) { return P(A.x+B.x,A.y+B.y); }
    friend P operator* (P A,double p) { return P(A.x*p,A.y*p); }
    friend P operator/ (P A,double p) { return P(A.x/p,A.y/p); }
    friend bool operator< (const P& a,const P& b) {return a.x<b.x||(a.x==b.x&& a.y<b.y);}

};
const double eps=1e-10;
int dcmp(double x) {
    if (fabs(x)<eps) return 0; else return x<0 ? -1 : 1;
}
bool operator==(const P& a,const P& b) {
    return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y) == 0;
}
typedef P V;

double Cross(V A,V B) {return A.x*B.y - A.y*B.x;}
double Area2(P A,P B,P C) {return Cross(B-A,C-A);}
V Rotate(V A,double rad) {
    return V(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
// A 不是 0向量
V Normal(V A) {
    double L = Length(A);
    return V(-A.y/L , A.x/L);
}

namespace complex_G{
    typedef complex<double> Point;
    //real(p):实部 imag(p):虚部 conj(p):共轭
    typedef Point Vector;
    double Dot(Vector A,Vector B) {return real(conj(A)*B); }
    double Cross(Vector A,Vector B) {return imag(conj(A)*B); }
    Vector Rotate(Vector A,double rad) {return A*exp(Point(0,rad)); }
}
//Cross(v,w)==0(平行)时,不能调这个函数
P GetLineIntersection(P p,V v,P Q,V w){
    V u = p-Q;
    double t = Cross(w,u)/Cross(v,w);
    return p+v*t;
}
P GetLineIntersectionB(P p,V v,P Q,V w){
    return GetLineIntersection(p,v-p,Q,w-Q);
}

double DistanceToLine(P p,P A,P B) {
    V v1 = B-A, v2 = p-A;
    return fabs(Cross(v1,v2))/Length(v1);
}
double DistanceToSegment(P p,P A,P B) {
    if (A==B) return Length(p-A);
    V v1 = B-A, v2 = p-A, v3 = p - B;
    if (dcmp(Dot(v1,v2))<0) return Length(v2);
    else if (dcmp(Dot(v1,v3))>0 ) return Length(v3);
    else return fabs(Cross(v1,v2) ) / Length(v1);
}
P GetLineProjection(P p,P A,P B) {
    V v=B-A;
    return A+v*(Dot(v,p-A)/Dot(v,v));
}
//规范相交-线段相交且交点不在端点
bool SegmentProperIntersection(P a1,P a2,P b1,P b2) {
    double  c1 = Cross(a2-a1,b1-a1) , c2 = Cross(a2-a1,b2-a1),
            c3 = Cross(b2-b1,a1-b1) , c4 = Cross(b2-b1,a2-b1);
    return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0;
}
//点在线段上(不包含端点)
bool OnSegment(P p,P a1,P a2) {
    return dcmp(Cross(a1-p,a2-p)) == 0 && dcmp(Dot(a1-p,a2-p))<0;
}
double PolygonArea(P *p,int n) {
    double area=0;
    For(i,n-2) area+=Cross(p[i]-p[0],p[i+1]-p[0]);
    return area/2;
}
/*欧拉公式: V+F-E=2
V-点数 F面数 E边数 */
P read_point() {
    P a;
    scanf("%lf%lf",&a.x,&a.y);
    return a;
}
struct C{
    P c;
    double r,x,y;
    C(P c,double r):c(c),r(r),x(c.x),y(c.y){}
    P point(double a) {
        return P(c.x+cos(a)*r,c.y+sin(a)*r);
    }
};

struct Line{
    P p;
    V v;
    double ang;
    Line(){}
    Line(P p,V v):p(p),v(v) {ang=atan2(v.y,v.x); }
    bool operator<(const Line & L) const {
        return ang<L.ang;
    }
    P point(double a) {
        return p+v*a;
    }
};
int getLineCircleIntersection(Line L,C cir,double &t1,double &t2,vector<P> & sol) {
    if (dcmp(DistanceToLine(cir.c,L.p,L.p+L.v)-cir.r)==0) {
        sol.pb(GetLineProjection(cir.c,L.p,L.p+L.v));
        return 1;
    }

    double a = L.v.x, b = L.p.x - cir.c.x, c = L.v.y, d= L.p.y - cir.c.y;
    double e = a*a+c*c, f = 2*(a*b + c*d), g = b*b+d*d-cir.r*cir.r;
    double delta = f*f - 4*e*g;
    if (dcmp(delta)<0) return 0;
    else if (dcmp(delta)==0) {
        t1 = t2 = -f / (2*e); sol.pb(L.point(t1));
        return 1;
    }
    t1 = (-f - sqrt(delta)) / (2*e); sol.pb(L.point(t1));
    t2 = (-f + sqrt(delta)) / (2*e); sol.pb(L.point(t2));
    return 2;
}
double angle(V v) {return atan2(v.y,v.x);}
int getCircleCircleIntersection(C C1,C C2,vector<P>& sol) {
    double d = Length(C1.c-C2.c);
    if (dcmp(d)==0) {
        if (dcmp(C1.r - C2.r)==0) return -1; //2圆重合
        return 0;
    }
    if (dcmp(C1.r+C2.r-d)<0) return 0;
    if (dcmp(fabs(C1.r-C2.r)-d)>0) return 0;

    double a = angle(C2.c-C1.c);
    double da = acos((C1.r*C1.r+d*d - C2.r*C2.r)/ (2*C1.r*d));
    P p1 = C1.point(a-da), p2 = C1.point(a+da);
    sol.pb(p1);
    if (p1==p2) return 1;
    sol.pb(p2);
    return 2;
}
// Tangents-切线
int getTangents(P p,C c,V* v) {
    V u= c.c-p;
    double dist = Length(u);
    if (dist<c.r) return 0;
    else if (dcmp(dist-c.r)==0) {
        v[0]=Rotate(u,PI/2);
        return 1;
    } else {
        double ang = asin(c.r / dist);
        v[0]=Rotate(u,-ang);
        v[1]=Rotate(u,ang);
        return 2;
    }
}
//这个函数假设整数坐标和整数半径
//double时要把int改成double
int getTangents(C A,C B,P* a,P* b) {
    int cnt=0;
    if (A.r<B.r) {swap(A,B),swap(a,b);}
    int d2 = (A.c.x-B.c.x)*(A.c.x-B.c.x) + (A.c.y-B.c.y)*(A.c.y-B.c.y);
    int rdiff = A.r-B.r;
    int rsum = A.r+B.r;
    if (d2<rdiff*rdiff) return 0;
    double base = atan2(B.y-A.y,B.x-A.x);
    if (d2==0 && A.r == B.r) return -1;
    if (d2 == rdiff*rdiff) {
        a[cnt] = A.point(base); b[cnt] = B.point(base); ++cnt;
        return 1;
    }
    double ang = acos((A.r-B.r)/sqrt(d2));
    a[cnt] = A.point(base+ang); b[cnt] = B.point(base+ang); ++cnt;
    a[cnt] = A.point(base-ang); b[cnt] = B.point(base-ang); ++cnt;
    if (d2==rsum*rsum) {
        a[cnt] = A.point(base); b[cnt] = B.point(PI+base); ++cnt;
    }
    else if (d2>rsum*rsum) {
        double ang = acos((A.r+B.r)/sqrt(d2));
        a[cnt] = A.point(base+ang); b[cnt] = B.point(PI+base+ang); ++cnt;
        a[cnt] = A.point(base-ang); b[cnt] = B.point(PI+base-ang); ++cnt;
    }
    return cnt;
}
//Circumscribed-外接
C CircumscribedCircle(P p1,P p2,P p3) {
    double Bx = p2.x-p1.x, By= p2.y-p1.y;
    double Cx = p3.x-p1.x, Cy= p3.y-p1.y;
    double D = 2*(Bx*Cy-By*Cx);
    double cx = (Cy*(Bx*Bx+By*By)-By*(Cx*Cx+Cy*Cy))/D + p1.x;
    double cy = (Bx*(Cx*Cx+Cy*Cy)-Cx*(Bx*Bx+By*By))/D + p1.y;
    P p =P(cx,cy);
    return C(p,Length(p1-p));
}
//Inscribed-内接
C InscribedCircle(P p1,P p2,P p3) {
    double a = Length(p2-p3);
    double b = Length(p3-p1);
    double c = Length(p1-p2);
    P p = (p1*a+p2*b+p3*c)/(a+b+c);
    return C(p,DistanceToLine(p,p1,p2));
}
double torad(double deg) {
    return deg/180*acos(-1);
}
//把 角度+-pi 转换到 [0,pi) 上
double radToPositive(double rad) {
    if (dcmp(rad)<0) rad=ceil(-rad/PI)*PI+rad;
    if (dcmp(rad-PI)>=0) rad-=floor(rad/PI)*PI;
    return rad;
}
double todeg(double rad) {
    return rad*180/acos(-1);
}

//(R,lat,lng)->(x,y,z)
void get_coord(double R,double lat,double lng,double &x,double &y,double &z) {
    lat=torad(lat);
    lng=torad(lng);
    x=R*cos(lat)*cos(lng);
    y=R*cos(lat)*sin(lng);
    z=R*sin(lat);
}
void print(double a) {
    printf("%.6lf",a);
}
void print(P p) {
    printf("(%.6lf,%.6lf)",p.x,p.y);
}
template<class T>
void print(vector<T> v) {
    sort(v.begin(),v.end());
    putchar(‘[‘);
    int n=v.size();
    Rep(i,n) {
        print(v[i]);
        if (i<n-1) putchar(‘,‘);
    }
    puts("]");
}
// 把直线沿v平移
// Translation-平移
Line LineTranslation(Line l,V v) {
    l.p=l.p+v;
    return l;
}
void CircleThroughAPointAndTangentToALineWithRadius(P p,Line l,double r,vector<P>& sol) {
    V e=Normal(l.v);
    Line l1=LineTranslation(l,e*r),l2=LineTranslation(l,e*(-r));
    double t1,t2;
    getLineCircleIntersection(l1,C(p,r),t1,t2,sol);
    getLineCircleIntersection(l2,C(p,r),t1,t2,sol);
}
void CircleTangentToTwoLinesWithRadius(Line l1,Line l2,double r,vector<P>& sol) {
    V e1=Normal(l1.v),e2=Normal(l2.v);
    Line L1[2]={LineTranslation(l1,e1*r),LineTranslation(l1,e1*(-r))},
         L2[2]={LineTranslation(l2,e2*r),LineTranslation(l2,e2*(-r))};
    Rep(i,2) Rep(j,2) sol.pb(GetLineIntersection(L1[i].p,L1[i].v,L2[j].p,L2[j].v));
}
void CircleTangentToTwoDisjointCirclesWithRadius(C c1,C c2,double r,vector<P>& sol) {
    c1.r+=r; c2.r+=r;
    getCircleCircleIntersection(c1,c2,sol);
}
//确定4个点能否组成凸多边形,并按顺序(不一定是逆时针)返回
bool ConvexPolygon(P &A,P &B,P &C,P &D) {
    if (SegmentProperIntersection(A,C,B,D)) return 1;
    swap(B,C);
    if (SegmentProperIntersection(A,C,B,D)) return 1;
    swap(D,C);
    if (SegmentProperIntersection(A,C,B,D)) return 1;
    return 0;
}
bool IsParallel(P A,P B,P C,P D) {
    return dcmp(Cross(B-A,D-C))==0;
}
bool IsPerpendicular(V A,V B) {
    return dcmp(Dot(A,B))==0;
}
//先调用ConvexPolygon 求凸包并确认是否是四边形
// Trapezium-梯形 Rhombus-菱形
bool IsTrapezium(P A,P B,P C,P D){
    return IsParallel(A,B,C,D)^IsParallel(B,C,A,D);
}
bool IsParallelogram(P A,P B,P C,P D) {
    return IsParallel(A,B,C,D)&&IsParallel(B,C,A,D);
}
bool IsRhombus(P A,P B,P C,P D) {
    return IsParallelogram(A,B,C,D)&&dcmp(Length(B-A)-Length(C-B))==0;
}
bool IsRectangle(P A,P B,P C,P D) {
    return IsParallelogram(A,B,C,D)&&IsPerpendicular(B-A,D-A);
}
bool IsSquare(P A,P B,P C,P D) {
    return IsParallelogram(A,B,C,D)&&IsPerpendicular(B-A,D-A)&&dcmp(Length(B-A)-Length(C-B))==0;
}

//chord-弦 arc-弧
double ArcDis(double chord,double r) {
    return 2*asin(chord/2/r)*r;
}
typedef vector<P> Polygon ;
int isPointInPolygon(P p,Polygon poly) {
    int wn=0;
    int n=poly.size();
    Rep(i,n) {
        if (OnSegment(p,poly[i],poly[(i+1)%n])) return -1;
        int k=dcmp(Cross(poly[(i+1)%n]-poly[i],p-poly[i]));
        int d1 = dcmp(poly[i].y-p.y);
        int d2 = dcmp(poly[(i+1)%n].y-p.y);
        if ( k > 0 && d1 <= 0 && d2 > 0 ) wn++;
        if ( k < 0 && d2 <= 0 && d1 > 0 ) wn--;
    }
    if (wn!=0) return 1;
    return 0;
}

int ConvexHull(P *p,int n,P *ch) {
    sort(p,p+n);
    int m=0;
    Rep(i,n) {
        while(m>1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
        ch[m++]=p[i];
    }
    int k=m;
    RepD(i,n-2) {
        while(m>k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
        ch[m++]=p[i];
    }
    if ( n > 1 ) m--;
    return m;
}
//把两点式转为一般式 ax+by+c=0
void Two_pointFormToGeneralForm(P A,P B,double &a,double &b,double &c){
    a = A.y - B.y;
    b = B.x - A.x;
    c = Cross(A,B);
}
//有向直线A->B 切割多边行poly 可能返回单点线段 O(n)
Polygon CutPolygon(Polygon poly,P A,P B){
    Polygon newpoly;
    int n=poly.size();
    Rep(i,n) {
        P C = poly[i];
        P D = poly[(i+1)%n];
        if (dcmp(Cross(B-A,C-A))>=0)  newpoly.pb(C);
        if (dcmp(Cross(B-A,C-D))) {
            P ip = GetLineIntersection(A,B-A,C,D-C);
            if (OnSegment(ip,C,D)) newpoly.pb(ip);
        }
    }
}
//线上不算
bool OnLeft(Line L,P p) {
    return Cross(L.v,p-L.p) > 0;
}
P GetIntersection(Line a,Line b) {
    V u=a.p-b.p;
    double t = Cross(b.v,u) / Cross(a.v, b.v);
    return a.p + a.v*t;
}
int HalfplaneIntersection(Line *L, int n, P* poly) {
    sort(L,L+n);
    int fi,la;
    P *p = new P[n];
    Line *q = new Line[n];
    q[fi=la=0 ] = L[0];
    For(i,n-1) {
        while (fi < la && !OnLeft(L[i],p[la-1])) la--;
        while (fi < la && !OnLeft(L[i],p[fi])) fi++;
        q[++la] = L[i];
        if (fabs(Cross(q[la].v, q[la-1].v))<eps) {
            la--;
            if (OnLeft(q[la],L[i].p)) q[la] = L[i];
        }
        if (fi<la) p[la-1] = GetIntersection(q[la-1],q[la]);
    }
    while(fi < la && !OnLeft(q[fi],p[la-1])) la--;
    if (la-fi<=1) return 0;
    p[la] = GetIntersection(q[la],q[fi]);

    int m=0;
    Fork(i,fi,la) poly[m++]=p[i];
    return m;
}
// hypot(double x,double y); return sqrt(x*x+y*y)

P p[200],poly[200];
Line L[200];
V v[200],v2[200];
int n;
int main()
{
//  freopen("uva1396.in","r",stdin);
//  freopen(".out","w",stdout);

    while(cin>>n&&n) {
        Rep(i,n) {
            p[i]=read_point();
        }
        Rep(i,n) {
            v[i] = p[(i+1)%n] - p[i];
            v2[i] = Normal(v[i]);
        }
        double l=0,r=20000;
        while(r-l>1e-7) {
            double m=(r+l)/2;
            Rep(i,n) L[i]=LineTranslation(Line(p[i],v[i]),v2[i]*m);
            if (!HalfplaneIntersection(L,n,poly)) r=m; else l=m;
        }
        printf("%.6lf\n",l);
    }

    return 0;
}

UVA 1298 Triathlon

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch==‘-‘) f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-‘0‘; ch=getchar();}
    return x*f;
}
ll sqr(ll a){return a*a;}
ld sqr(ld a){return a*a;}
double sqr(double a){return a*a;}

ld PI = 3.141592653589793238462643383;
class P{
public:
    double x,y;
    P(double x=0,double y=0):x(x),y(y){}
    friend long double dis2(P A,P B){return sqr(A.x-B.x)+sqr(A.y-B.y);  }
    friend long double Dot(P A,P B) {return A.x*B.x+A.y*B.y; }
    friend long double Length(P A) {return sqrt(Dot(A,A)); }
    friend long double Angle(P A,P B) {return acos(Dot(A,B) / Length(A) / Length(B) ); }

    friend P operator- (P A,P B) { return P(A.x-B.x,A.y-B.y); }
    friend P operator+ (P A,P B) { return P(A.x+B.x,A.y+B.y); }
    friend P operator* (P A,double p) { return P(A.x*p,A.y*p); }
    friend P operator/ (P A,double p) { return P(A.x/p,A.y/p); }
    friend bool operator< (const P& a,const P& b) {return a.x<b.x||(a.x==b.x&& a.y<b.y);}

};
const double eps=1e-10;
int dcmp(double x) {
    if (fabs(x)<eps) return 0; else return x<0 ? -1 : 1;
}
bool operator==(const P& a,const P& b) {
    return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y) == 0;
}
typedef P V;

double Cross(V A,V B) {return A.x*B.y - A.y*B.x;}
double Area2(P A,P B,P C) {return Cross(B-A,C-A);}
V Rotate(V A,double rad) {
    return V(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
// A 不是 0向量
V Normal(V A) {
    double L = Length(A);
    return V(-A.y/L , A.x/L);
}

namespace complex_G{
    typedef complex<double> Point;
    //real(p):实部 imag(p):虚部 conj(p):共轭
    typedef Point Vector;
    double Dot(Vector A,Vector B) {return real(conj(A)*B); }
    double Cross(Vector A,Vector B) {return imag(conj(A)*B); }
    Vector Rotate(Vector A,double rad) {return A*exp(Point(0,rad)); }
}
//Cross(v,w)==0(平行)时,不能调这个函数
P GetLineIntersection(P p,V v,P Q,V w){
    V u = p-Q;
    double t = Cross(w,u)/Cross(v,w);
    return p+v*t;
}
P GetLineIntersectionB(P p,V v,P Q,V w){
    return GetLineIntersection(p,v-p,Q,w-Q);
}

double DistanceToLine(P p,P A,P B) {
    V v1 = B-A, v2 = p-A;
    return fabs(Cross(v1,v2))/Length(v1);
}
double DistanceToSegment(P p,P A,P B) {
    if (A==B) return Length(p-A);
    V v1 = B-A, v2 = p-A, v3 = p - B;
    if (dcmp(Dot(v1,v2))<0) return Length(v2);
    else if (dcmp(Dot(v1,v3))>0 ) return Length(v3);
    else return fabs(Cross(v1,v2) ) / Length(v1);
}
P GetLineProjection(P p,P A,P B) {
    V v=B-A;
    return A+v*(Dot(v,p-A)/Dot(v,v));
}
//规范相交-线段相交且交点不在端点
bool SegmentProperIntersection(P a1,P a2,P b1,P b2) {
    double  c1 = Cross(a2-a1,b1-a1) , c2 = Cross(a2-a1,b2-a1),
            c3 = Cross(b2-b1,a1-b1) , c4 = Cross(b2-b1,a2-b1);
    return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0;
}
//点在线段上(不包含端点)
bool OnSegment(P p,P a1,P a2) {
    return dcmp(Cross(a1-p,a2-p)) == 0 && dcmp(Dot(a1-p,a2-p))<0;
}
double PolygonArea(P *p,int n) {
    double area=0;
    For(i,n-2) area+=Cross(p[i]-p[0],p[i+1]-p[0]);
    return area/2;
}
/*欧拉公式: V+F-E=2
V-点数 F面数 E边数 */
P read_point() {
    P a;
    scanf("%lf%lf",&a.x,&a.y);
    return a;
}
struct C{
    P c;
    double r,x,y;
    C(P c,double r):c(c),r(r),x(c.x),y(c.y){}
    P point(double a) {
        return P(c.x+cos(a)*r,c.y+sin(a)*r);
    }
};

struct Line{
    P p;
    V v;
    double ang;
    Line(){}
    Line(P p,V v):p(p),v(v) {ang=atan2(v.y,v.x); }
    bool operator<(const Line & L) const {
        return ang<L.ang;
    }
    P point(double a) {
        return p+v*a;
    }
};
int getLineCircleIntersection(Line L,C cir,double &t1,double &t2,vector<P> & sol) {
    if (dcmp(DistanceToLine(cir.c,L.p,L.p+L.v)-cir.r)==0) {
        sol.pb(GetLineProjection(cir.c,L.p,L.p+L.v));
        return 1;
    }

    double a = L.v.x, b = L.p.x - cir.c.x, c = L.v.y, d= L.p.y - cir.c.y;
    double e = a*a+c*c, f = 2*(a*b + c*d), g = b*b+d*d-cir.r*cir.r;
    double delta = f*f - 4*e*g;
    if (dcmp(delta)<0) return 0;
    else if (dcmp(delta)==0) {
        t1 = t2 = -f / (2*e); sol.pb(L.point(t1));
        return 1;
    }
    t1 = (-f - sqrt(delta)) / (2*e); sol.pb(L.point(t1));
    t2 = (-f + sqrt(delta)) / (2*e); sol.pb(L.point(t2));
    return 2;
}
double angle(V v) {return atan2(v.y,v.x);}
int getCircleCircleIntersection(C C1,C C2,vector<P>& sol) {
    double d = Length(C1.c-C2.c);
    if (dcmp(d)==0) {
        if (dcmp(C1.r - C2.r)==0) return -1; //2圆重合
        return 0;
    }
    if (dcmp(C1.r+C2.r-d)<0) return 0;
    if (dcmp(fabs(C1.r-C2.r)-d)>0) return 0;

    double a = angle(C2.c-C1.c);
    double da = acos((C1.r*C1.r+d*d - C2.r*C2.r)/ (2*C1.r*d));
    P p1 = C1.point(a-da), p2 = C1.point(a+da);
    sol.pb(p1);
    if (p1==p2) return 1;
    sol.pb(p2);
    return 2;
}
// Tangents-切线
int getTangents(P p,C c,V* v) {
    V u= c.c-p;
    double dist = Length(u);
    if (dist<c.r) return 0;
    else if (dcmp(dist-c.r)==0) {
        v[0]=Rotate(u,PI/2);
        return 1;
    } else {
        double ang = asin(c.r / dist);
        v[0]=Rotate(u,-ang);
        v[1]=Rotate(u,ang);
        return 2;
    }
}
//这个函数假设整数坐标和整数半径
//double时要把int改成double
int getTangents(C A,C B,P* a,P* b) {
    int cnt=0;
    if (A.r<B.r) {swap(A,B),swap(a,b);}
    int d2 = (A.c.x-B.c.x)*(A.c.x-B.c.x) + (A.c.y-B.c.y)*(A.c.y-B.c.y);
    int rdiff = A.r-B.r;
    int rsum = A.r+B.r;
    if (d2<rdiff*rdiff) return 0;
    double base = atan2(B.y-A.y,B.x-A.x);
    if (d2==0 && A.r == B.r) return -1;
    if (d2 == rdiff*rdiff) {
        a[cnt] = A.point(base); b[cnt] = B.point(base); ++cnt;
        return 1;
    }
    double ang = acos((A.r-B.r)/sqrt(d2));
    a[cnt] = A.point(base+ang); b[cnt] = B.point(base+ang); ++cnt;
    a[cnt] = A.point(base-ang); b[cnt] = B.point(base-ang); ++cnt;
    if (d2==rsum*rsum) {
        a[cnt] = A.point(base); b[cnt] = B.point(PI+base); ++cnt;
    }
    else if (d2>rsum*rsum) {
        double ang = acos((A.r+B.r)/sqrt(d2));
        a[cnt] = A.point(base+ang); b[cnt] = B.point(PI+base+ang); ++cnt;
        a[cnt] = A.point(base-ang); b[cnt] = B.point(PI+base-ang); ++cnt;
    }
    return cnt;
}
//Circumscribed-外接
C CircumscribedCircle(P p1,P p2,P p3) {
    double Bx = p2.x-p1.x, By= p2.y-p1.y;
    double Cx = p3.x-p1.x, Cy= p3.y-p1.y;
    double D = 2*(Bx*Cy-By*Cx);
    double cx = (Cy*(Bx*Bx+By*By)-By*(Cx*Cx+Cy*Cy))/D + p1.x;
    double cy = (Bx*(Cx*Cx+Cy*Cy)-Cx*(Bx*Bx+By*By))/D + p1.y;
    P p =P(cx,cy);
    return C(p,Length(p1-p));
}
//Inscribed-内接
C InscribedCircle(P p1,P p2,P p3) {
    double a = Length(p2-p3);
    double b = Length(p3-p1);
    double c = Length(p1-p2);
    P p = (p1*a+p2*b+p3*c)/(a+b+c);
    return C(p,DistanceToLine(p,p1,p2));
}
double torad(double deg) {
    return deg/180*acos(-1);
}
//把 角度+-pi 转换到 [0,pi) 上
double radToPositive(double rad) {
    if (dcmp(rad)<0) rad=ceil(-rad/PI)*PI+rad;
    if (dcmp(rad-PI)>=0) rad-=floor(rad/PI)*PI;
    return rad;
}
double todeg(double rad) {
    return rad*180/acos(-1);
}

//(R,lat,lng)->(x,y,z)
void get_coord(double R,double lat,double lng,double &x,double &y,double &z) {
    lat=torad(lat);
    lng=torad(lng);
    x=R*cos(lat)*cos(lng);
    y=R*cos(lat)*sin(lng);
    z=R*sin(lat);
}
void print(double a) {
    printf("%.6lf",a);
}
void print(P p) {
    printf("(%.6lf,%.6lf)",p.x,p.y);
}
template<class T>
void print(vector<T> v) {
    sort(v.begin(),v.end());
    putchar(‘[‘);
    int n=v.size();
    Rep(i,n) {
        print(v[i]);
        if (i<n-1) putchar(‘,‘);
    }
    puts("]");
}
// 把直线沿v平移
// Translation-平移
Line LineTranslation(Line l,V v) {
    l.p=l.p+v;
    return l;
}
void CircleThroughAPointAndTangentToALineWithRadius(P p,Line l,double r,vector<P>& sol) {
    V e=Normal(l.v);
    Line l1=LineTranslation(l,e*r),l2=LineTranslation(l,e*(-r));
    double t1,t2;
    getLineCircleIntersection(l1,C(p,r),t1,t2,sol);
    getLineCircleIntersection(l2,C(p,r),t1,t2,sol);
}
void CircleTangentToTwoLinesWithRadius(Line l1,Line l2,double r,vector<P>& sol) {
    V e1=Normal(l1.v),e2=Normal(l2.v);
    Line L1[2]={LineTranslation(l1,e1*r),LineTranslation(l1,e1*(-r))},
         L2[2]={LineTranslation(l2,e2*r),LineTranslation(l2,e2*(-r))};
    Rep(i,2) Rep(j,2) sol.pb(GetLineIntersection(L1[i].p,L1[i].v,L2[j].p,L2[j].v));
}
void CircleTangentToTwoDisjointCirclesWithRadius(C c1,C c2,double r,vector<P>& sol) {
    c1.r+=r; c2.r+=r;
    getCircleCircleIntersection(c1,c2,sol);
}
//确定4个点能否组成凸多边形,并按顺序(不一定是逆时针)返回
bool ConvexPolygon(P &A,P &B,P &C,P &D) {
    if (SegmentProperIntersection(A,C,B,D)) return 1;
    swap(B,C);
    if (SegmentProperIntersection(A,C,B,D)) return 1;
    swap(D,C);
    if (SegmentProperIntersection(A,C,B,D)) return 1;
    return 0;
}
bool IsParallel(P A,P B,P C,P D) {
    return dcmp(Cross(B-A,D-C))==0;
}
bool IsPerpendicular(V A,V B) {
    return dcmp(Dot(A,B))==0;
}
//先调用ConvexPolygon 求凸包并确认是否是四边形
// Trapezium-梯形 Rhombus-菱形
bool IsTrapezium(P A,P B,P C,P D){
    return IsParallel(A,B,C,D)^IsParallel(B,C,A,D);
}
bool IsParallelogram(P A,P B,P C,P D) {
    return IsParallel(A,B,C,D)&&IsParallel(B,C,A,D);
}
bool IsRhombus(P A,P B,P C,P D) {
    return IsParallelogram(A,B,C,D)&&dcmp(Length(B-A)-Length(C-B))==0;
}
bool IsRectangle(P A,P B,P C,P D) {
    return IsParallelogram(A,B,C,D)&&IsPerpendicular(B-A,D-A);
}
bool IsSquare(P A,P B,P C,P D) {
    return IsParallelogram(A,B,C,D)&&IsPerpendicular(B-A,D-A)&&dcmp(Length(B-A)-Length(C-B))==0;
}

//chord-弦 arc-弧
double ArcDis(double chord,double r) {
    return 2*asin(chord/2/r)*r;
}
typedef vector<P> Polygon ;
int isPointInPolygon(P p,Polygon poly) {
    int wn=0;
    int n=poly.size();
    Rep(i,n) {
        if (OnSegment(p,poly[i],poly[(i+1)%n])) return -1;
        int k=dcmp(Cross(poly[(i+1)%n]-poly[i],p-poly[i]));
        int d1 = dcmp(poly[i].y-p.y);
        int d2 = dcmp(poly[(i+1)%n].y-p.y);
        if ( k > 0 && d1 <= 0 && d2 > 0 ) wn++;
        if ( k < 0 && d2 <= 0 && d1 > 0 ) wn--;
    }
    if (wn!=0) return 1;
    return 0;
}

int ConvexHull(P *p,int n,P *ch) {
    sort(p,p+n);
    int m=0;
    Rep(i,n) {
        while(m>1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
        ch[m++]=p[i];
    }
    int k=m;
    RepD(i,n-2) {
        while(m>k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
        ch[m++]=p[i];
    }
    if ( n > 1 ) m--;
    return m;
}
//把两点式转为一般式 ax+by+c=0
void Two_pointFormToGeneralForm(P A,P B,double &a,double &b,double &c){
    a = A.y - B.y;
    b = B.x - A.x;
    c = Cross(A,B);
}
//ax+by+c>0 的 P,V有向线段
void GeneralFormToPointVectorForm(P &p,V &v,double a,double b,double c){
    v=V(b,-a);
    if (fabs(a)>fabs(b)) p=P(-c/a,0);
    else p=P(0,-c/b);
}

//有向直线A->B 切割多边行poly 可能返回单点线段 O(n)
Polygon CutPolygon(Polygon poly,P A,P B){
    Polygon newpoly;
    int n=poly.size();
    Rep(i,n) {
        P C = poly[i];
        P D = poly[(i+1)%n];
        if (dcmp(Cross(B-A,C-A))>=0)  newpoly.pb(C);
        if (dcmp(Cross(B-A,C-D))) {
            P ip = GetLineIntersection(A,B-A,C,D-C);
            if (OnSegment(ip,C,D)) newpoly.pb(ip);
        }
    }
}
//线上不算
bool OnLeft(Line L,P p) {
    return Cross(L.v,p-L.p) > 0;
}
P GetIntersection(Line a,Line b) {
    V u=a.p-b.p;
    double t = Cross(b.v,u) / Cross(a.v, b.v);
    return a.p + a.v*t;
}
int HalfplaneIntersection(Line *L, int n, P* poly) {
    sort(L,L+n);
    int fi,la;
    P *p = new P[n];
    Line *q = new Line[n];
    q[fi=la=0 ] = L[0];
    For(i,n-1) {
        while (fi < la && !OnLeft(L[i],p[la-1])) la--;
        while (fi < la && !OnLeft(L[i],p[fi])) fi++;
        q[++la] = L[i];
        if (fabs(Cross(q[la].v, q[la-1].v))<eps) {
            la--;
            if (OnLeft(q[la],L[i].p)) q[la] = L[i];
        }
        if (fi<la) p[la-1] = GetIntersection(q[la-1],q[la]);
    }
    while(fi < la && !OnLeft(q[fi],p[la-1])) la--;
    if (la-fi<=1) return 0;
    p[la] = GetIntersection(q[la],q[fi]);

    int m=0;
    Fork(i,fi,la) poly[m++]=p[i];
    return m;
}
// hypot(double x,double y); return sqrt(x*x+y*y)

int v[200],u[200],w[200];
P p[200],poly[200];
Line L[200];
int n;
int main()
{
    freopen("uva1298.in","r",stdin);
//  freopen(".out","w",stdout);

    while(cin>>n&&n) {
        Rep(i,n) {
            cin>>v[i]>>u[i]>>w[i];
        }
        Rep(i,n) {
            bool flag=0;
            double k=10000;
            int lc=0;
            Rep(j,n) if (i^j) {
                if(v[i]<=v[j]&&u[i]<=u[j]&&w[i]<=w[j]) {
                    flag=1; break;
                }
                if (v[i]>=v[j]&&u[i]>=u[j]&&w[i]>=w[j]) continue;
                double a=k/v[j]-k/w[j]-(k/v[i]-k/w[i]);
                double b=k/u[j]-k/w[j]-(k/u[i]-k/w[i]);
                double c=k/w[j]-k/w[i];
                P p1,v1;
                GeneralFormToPointVectorForm(p1,v1,a,b,c);
                L[lc++] = Line(p1,v1);
            }
            if (!flag) {
                L[lc++] = Line(P(0,0),V(1,0));
                L[lc++] = Line(P(0,0),V(0,-1));
                L[lc++] = Line(P(0,1),V(-1,1));
                if (!HalfplaneIntersection(L,lc,poly)) flag=1;
            }
            if (!flag) puts("Yes"); else puts("No"); 

        }
    }

    return 0;
}

UVA 1475 Jungle Outpost

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch==‘-‘) f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-‘0‘; ch=getchar();}
    return x*f;
}
ll sqr(ll a){return a*a;}
ld sqr(ld a){return a*a;}
double sqr(double a){return a*a;}

ld PI = 3.141592653589793238462643383;
class P{
public:
    double x,y;
    P(double x=0,double y=0):x(x),y(y){}
    friend long double dis2(P A,P B){return sqr(A.x-B.x)+sqr(A.y-B.y);  }
    friend long double Dot(P A,P B) {return A.x*B.x+A.y*B.y; }
    friend long double Length(P A) {return sqrt(Dot(A,A)); }
    friend long double Angle(P A,P B) {return acos(Dot(A,B) / Length(A) / Length(B) ); }

    friend P operator- (P A,P B) { return P(A.x-B.x,A.y-B.y); }
    friend P operator+ (P A,P B) { return P(A.x+B.x,A.y+B.y); }
    friend P operator* (P A,double p) { return P(A.x*p,A.y*p); }
    friend P operator/ (P A,double p) { return P(A.x/p,A.y/p); }
    friend bool operator< (const P& a,const P& b) {return a.x<b.x||(a.x==b.x&& a.y<b.y);}

};
const double eps=1e-10;
int dcmp(double x) {
    if (fabs(x)<eps) return 0; else return x<0 ? -1 : 1;
}
bool operator==(const P& a,const P& b) {
    return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y) == 0;
}
typedef P V;

double Cross(V A,V B) {return A.x*B.y - A.y*B.x;}
double Area2(P A,P B,P C) {return Cross(B-A,C-A);}
V Rotate(V A,double rad) {
    return V(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
// A 不是 0向量
V Normal(V A) {
    double L = Length(A);
    return V(-A.y/L , A.x/L);
}

namespace complex_G{
    typedef complex<double> Point;
    //real(p):实部 imag(p):虚部 conj(p):共轭
    typedef Point Vector;
    double Dot(Vector A,Vector B) {return real(conj(A)*B); }
    double Cross(Vector A,Vector B) {return imag(conj(A)*B); }
    Vector Rotate(Vector A,double rad) {return A*exp(Point(0,rad)); }
}
//Cross(v,w)==0(平行)时,不能调这个函数
P GetLineIntersection(P p,V v,P Q,V w){
    V u = p-Q;
    double t = Cross(w,u)/Cross(v,w);
    return p+v*t;
}
P GetLineIntersectionB(P p,V v,P Q,V w){
    return GetLineIntersection(p,v-p,Q,w-Q);
}

double DistanceToLine(P p,P A,P B) {
    V v1 = B-A, v2 = p-A;
    return fabs(Cross(v1,v2))/Length(v1);
}
double DistanceToSegment(P p,P A,P B) {
    if (A==B) return Length(p-A);
    V v1 = B-A, v2 = p-A, v3 = p - B;
    if (dcmp(Dot(v1,v2))<0) return Length(v2);
    else if (dcmp(Dot(v1,v3))>0 ) return Length(v3);
    else return fabs(Cross(v1,v2) ) / Length(v1);
}
P GetLineProjection(P p,P A,P B) {
    V v=B-A;
    return A+v*(Dot(v,p-A)/Dot(v,v));
}
//规范相交-线段相交且交点不在端点
bool SegmentProperIntersection(P a1,P a2,P b1,P b2) {
    double  c1 = Cross(a2-a1,b1-a1) , c2 = Cross(a2-a1,b2-a1),
            c3 = Cross(b2-b1,a1-b1) , c4 = Cross(b2-b1,a2-b1);
    return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0;
}
//点在线段上(不包含端点)
bool OnSegment(P p,P a1,P a2) {
    return dcmp(Cross(a1-p,a2-p)) == 0 && dcmp(Dot(a1-p,a2-p))<0;
}
double PolygonArea(P *p,int n) {
    double area=0;
    For(i,n-2) area+=Cross(p[i]-p[0],p[i+1]-p[0]);
    return area/2;
}
/*欧拉公式: V+F-E=2
V-点数 F面数 E边数 */
P read_point() {
    P a;
    scanf("%lf%lf",&a.x,&a.y);
    return a;
}
struct C{
    P c;
    double r,x,y;
    C(P c,double r):c(c),r(r),x(c.x),y(c.y){}
    P point(double a) {
        return P(c.x+cos(a)*r,c.y+sin(a)*r);
    }
};

struct Line{
    P p;
    V v;
    double ang;
    Line(){}
    Line(P p,V v):p(p),v(v) {ang=atan2(v.y,v.x); }
    bool operator<(const Line & L) const {
        return ang<L.ang;
    }
    P point(double a) {
        return p+v*a;
    }
};
int getLineCircleIntersection(Line L,C cir,double &t1,double &t2,vector<P> & sol) {
    if (dcmp(DistanceToLine(cir.c,L.p,L.p+L.v)-cir.r)==0) {
        sol.pb(GetLineProjection(cir.c,L.p,L.p+L.v));
        return 1;
    }

    double a = L.v.x, b = L.p.x - cir.c.x, c = L.v.y, d= L.p.y - cir.c.y;
    double e = a*a+c*c, f = 2*(a*b + c*d), g = b*b+d*d-cir.r*cir.r;
    double delta = f*f - 4*e*g;
    if (dcmp(delta)<0) return 0;
    else if (dcmp(delta)==0) {
        t1 = t2 = -f / (2*e); sol.pb(L.point(t1));
        return 1;
    }
    t1 = (-f - sqrt(delta)) / (2*e); sol.pb(L.point(t1));
    t2 = (-f + sqrt(delta)) / (2*e); sol.pb(L.point(t2));
    return 2;
}
double angle(V v) {return atan2(v.y,v.x);}
int getCircleCircleIntersection(C C1,C C2,vector<P>& sol) {
    double d = Length(C1.c-C2.c);
    if (dcmp(d)==0) {
        if (dcmp(C1.r - C2.r)==0) return -1; //2圆重合
        return 0;
    }
    if (dcmp(C1.r+C2.r-d)<0) return 0;
    if (dcmp(fabs(C1.r-C2.r)-d)>0) return 0;

    double a = angle(C2.c-C1.c);
    double da = acos((C1.r*C1.r+d*d - C2.r*C2.r)/ (2*C1.r*d));
    P p1 = C1.point(a-da), p2 = C1.point(a+da);
    sol.pb(p1);
    if (p1==p2) return 1;
    sol.pb(p2);
    return 2;
}
// Tangents-切线
int getTangents(P p,C c,V* v) {
    V u= c.c-p;
    double dist = Length(u);
    if (dist<c.r) return 0;
    else if (dcmp(dist-c.r)==0) {
        v[0]=Rotate(u,PI/2);
        return 1;
    } else {
        double ang = asin(c.r / dist);
        v[0]=Rotate(u,-ang);
        v[1]=Rotate(u,ang);
        return 2;
    }
}
//这个函数假设整数坐标和整数半径
//double时要把int改成double
int getTangents(C A,C B,P* a,P* b) {
    int cnt=0;
    if (A.r<B.r) {swap(A,B),swap(a,b);}
    int d2 = (A.c.x-B.c.x)*(A.c.x-B.c.x) + (A.c.y-B.c.y)*(A.c.y-B.c.y);
    int rdiff = A.r-B.r;
    int rsum = A.r+B.r;
    if (d2<rdiff*rdiff) return 0;
    double base = atan2(B.y-A.y,B.x-A.x);
    if (d2==0 && A.r == B.r) return -1;
    if (d2 == rdiff*rdiff) {
        a[cnt] = A.point(base); b[cnt] = B.point(base); ++cnt;
        return 1;
    }
    double ang = acos((A.r-B.r)/sqrt(d2));
    a[cnt] = A.point(base+ang); b[cnt] = B.point(base+ang); ++cnt;
    a[cnt] = A.point(base-ang); b[cnt] = B.point(base-ang); ++cnt;
    if (d2==rsum*rsum) {
        a[cnt] = A.point(base); b[cnt] = B.point(PI+base); ++cnt;
    }
    else if (d2>rsum*rsum) {
        double ang = acos((A.r+B.r)/sqrt(d2));
        a[cnt] = A.point(base+ang); b[cnt] = B.point(PI+base+ang); ++cnt;
        a[cnt] = A.point(base-ang); b[cnt] = B.point(PI+base-ang); ++cnt;
    }
    return cnt;
}
//Circumscribed-外接
C CircumscribedCircle(P p1,P p2,P p3) {
    double Bx = p2.x-p1.x, By= p2.y-p1.y;
    double Cx = p3.x-p1.x, Cy= p3.y-p1.y;
    double D = 2*(Bx*Cy-By*Cx);
    double cx = (Cy*(Bx*Bx+By*By)-By*(Cx*Cx+Cy*Cy))/D + p1.x;
    double cy = (Bx*(Cx*Cx+Cy*Cy)-Cx*(Bx*Bx+By*By))/D + p1.y;
    P p =P(cx,cy);
    return C(p,Length(p1-p));
}
//Inscribed-内接
C InscribedCircle(P p1,P p2,P p3) {
    double a = Length(p2-p3);
    double b = Length(p3-p1);
    double c = Length(p1-p2);
    P p = (p1*a+p2*b+p3*c)/(a+b+c);
    return C(p,DistanceToLine(p,p1,p2));
}
double torad(double deg) {
    return deg/180*acos(-1);
}
//把 角度+-pi 转换到 [0,pi) 上
double radToPositive(double rad) {
    if (dcmp(rad)<0) rad=ceil(-rad/PI)*PI+rad;
    if (dcmp(rad-PI)>=0) rad-=floor(rad/PI)*PI;
    return rad;
}
double todeg(double rad) {
    return rad*180/acos(-1);
}

//(R,lat,lng)->(x,y,z)
void get_coord(double R,double lat,double lng,double &x,double &y,double &z) {
    lat=torad(lat);
    lng=torad(lng);
    x=R*cos(lat)*cos(lng);
    y=R*cos(lat)*sin(lng);
    z=R*sin(lat);
}
void print(double a) {
    printf("%.6lf",a);
}
void print(P p) {
    printf("(%.6lf,%.6lf)",p.x,p.y);
}
template<class T>
void print(vector<T> v) {
    sort(v.begin(),v.end());
    putchar(‘[‘);
    int n=v.size();
    Rep(i,n) {
        print(v[i]);
        if (i<n-1) putchar(‘,‘);
    }
    puts("]");
}
// 把直线沿v平移
// Translation-平移
Line LineTranslation(Line l,V v) {
    l.p=l.p+v;
    return l;
}
void CircleThroughAPointAndTangentToALineWithRadius(P p,Line l,double r,vector<P>& sol) {
    V e=Normal(l.v);
    Line l1=LineTranslation(l,e*r),l2=LineTranslation(l,e*(-r));
    double t1,t2;
    getLineCircleIntersection(l1,C(p,r),t1,t2,sol);
    getLineCircleIntersection(l2,C(p,r),t1,t2,sol);
}
void CircleTangentToTwoLinesWithRadius(Line l1,Line l2,double r,vector<P>& sol) {
    V e1=Normal(l1.v),e2=Normal(l2.v);
    Line L1[2]={LineTranslation(l1,e1*r),LineTranslation(l1,e1*(-r))},
         L2[2]={LineTranslation(l2,e2*r),LineTranslation(l2,e2*(-r))};
    Rep(i,2) Rep(j,2) sol.pb(GetLineIntersection(L1[i].p,L1[i].v,L2[j].p,L2[j].v));
}
void CircleTangentToTwoDisjointCirclesWithRadius(C c1,C c2,double r,vector<P>& sol) {
    c1.r+=r; c2.r+=r;
    getCircleCircleIntersection(c1,c2,sol);
}
//确定4个点能否组成凸多边形,并按顺序(不一定是逆时针)返回
bool ConvexPolygon(P &A,P &B,P &C,P &D) {
    if (SegmentProperIntersection(A,C,B,D)) return 1;
    swap(B,C);
    if (SegmentProperIntersection(A,C,B,D)) return 1;
    swap(D,C);
    if (SegmentProperIntersection(A,C,B,D)) return 1;
    return 0;
}
bool IsParallel(P A,P B,P C,P D) {
    return dcmp(Cross(B-A,D-C))==0;
}
bool IsPerpendicular(V A,V B) {
    return dcmp(Dot(A,B))==0;
}
//先调用ConvexPolygon 求凸包并确认是否是四边形
// Trapezium-梯形 Rhombus-菱形
bool IsTrapezium(P A,P B,P C,P D){
    return IsParallel(A,B,C,D)^IsParallel(B,C,A,D);
}
bool IsParallelogram(P A,P B,P C,P D) {
    return IsParallel(A,B,C,D)&&IsParallel(B,C,A,D);
}
bool IsRhombus(P A,P B,P C,P D) {
    return IsParallelogram(A,B,C,D)&&dcmp(Length(B-A)-Length(C-B))==0;
}
bool IsRectangle(P A,P B,P C,P D) {
    return IsParallelogram(A,B,C,D)&&IsPerpendicular(B-A,D-A);
}
bool IsSquare(P A,P B,P C,P D) {
    return IsParallelogram(A,B,C,D)&&IsPerpendicular(B-A,D-A)&&dcmp(Length(B-A)-Length(C-B))==0;
}

//chord-弦 arc-弧
double ArcDis(double chord,double r) {
    return 2*asin(chord/2/r)*r;
}
typedef vector<P> Polygon ;
int isPointInPolygon(P p,Polygon poly) {
    int wn=0;
    int n=poly.size();
    Rep(i,n) {
        if (OnSegment(p,poly[i],poly[(i+1)%n])) return -1;
        int k=dcmp(Cross(poly[(i+1)%n]-poly[i],p-poly[i]));
        int d1 = dcmp(poly[i].y-p.y);
        int d2 = dcmp(poly[(i+1)%n].y-p.y);
        if ( k > 0 && d1 <= 0 && d2 > 0 ) wn++;
        if ( k < 0 && d2 <= 0 && d1 > 0 ) wn--;
    }
    if (wn!=0) return 1;
    return 0;
}

int ConvexHull(P *p,int n,P *ch) {
    sort(p,p+n);
    int m=0;
    Rep(i,n) {
        while(m>1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
        ch[m++]=p[i];
    }
    int k=m;
    RepD(i,n-2) {
        while(m>k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
        ch[m++]=p[i];
    }
    if ( n > 1 ) m--;
    return m;
}
//把两点式转为一般式 ax+by+c=0
void Two_pointFormToGeneralForm(P A,P B,double &a,double &b,double &c){
    a = A.y - B.y;
    b = B.x - A.x;
    c = Cross(A,B);
}
//ax+by+c>0 的 P,V有向线段
void GeneralFormToPointVectorForm(P &p,V &v,double a,double b,double c){
    v=V(b,-a);
    if (fabs(a)>fabs(b)) p=P(-c/a,0);
    else p=P(0,-c/b);
}

//有向直线A->B 切割多边行poly 可能返回单点线段 O(n)
Polygon CutPolygon(Polygon poly,P A,P B){
    Polygon newpoly;
    int n=poly.size();
    Rep(i,n) {
        P C = poly[i];
        P D = poly[(i+1)%n];
        if (dcmp(Cross(B-A,C-A))>=0)  newpoly.pb(C);
        if (dcmp(Cross(B-A,C-D))) {
            P ip = GetLineIntersection(A,B-A,C,D-C);
            if (OnSegment(ip,C,D)) newpoly.pb(ip);
        }
    }
}
//线上不算
bool OnLeft(Line L,P p) {
    return Cross(L.v,p-L.p) > 0;
}
P GetIntersection(Line a,Line b) {
    V u=a.p-b.p;
    double t = Cross(b.v,u) / Cross(a.v, b.v);
    return a.p + a.v*t;
}
int HalfplaneIntersection(Line *L, int n, P* poly) {
    sort(L,L+n);
    int fi,la;
    P *p = new P[n];
    Line *q = new Line[n];
    q[fi=la=0 ] = L[0];
    For(i,n-1) {
        while (fi < la && !OnLeft(L[i],p[la-1])) la--;
        while (fi < la && !OnLeft(L[i],p[fi])) fi++;
        q[++la] = L[i];
        if (fabs(Cross(q[la].v, q[la-1].v))<eps) {
            la--;
            if (OnLeft(q[la],L[i].p)) q[la] = L[i];
        }
        if (fi<la) p[la-1] = GetIntersection(q[la-1],q[la]);
    }
    while(fi < la && !OnLeft(q[fi],p[la-1])) la--;
    if (la-fi<=1) return 0;
    p[la] = GetIntersection(q[la],q[fi]);

    int m=0;
    Fork(i,fi,la) poly[m++]=p[i];
    return m;
}
// hypot(double x,double y); return sqrt(x*x+y*y)
#define MAXN (50000+10)
P p[MAXN],poly[MAXN];
Line L[MAXN];
int n;
int main()
{
//  freopen("uva1475.in","r",stdin);
//  freopen(".out","w",stdout);

    while(cin>>n) {
        Rep(i,n) {
            p[i]=read_point();
        }
        int l=0,r=n-2,ans=n-2;
        while(l<=r) {
            int m=(l+r)/2;
            int lc=0;
            Rep(i,n) {
                P A=p[i];
                P B=p[(i+1+m)%n];
                L[lc++] = Line(B,A-B);
            }
            if(!HalfplaneIntersection(L,lc,poly)) r=m-1,ans=m;else l=m+1;
        }

        cout<<ans<<endl;

    }

    return 0;
}
时间: 2024-11-05 04:57:02

几何算法专题的相关文章

[算法专题] LinkedList

前段时间在看一本01年出的旧书<effective Tcp/Ip programming>,这个算法专题中断了几天,现在继续写下去. Introduction 对于单向链表(singly linked list),每个节点有?个next指针指向后一个节点,还有一个成员变量用以储存数值:对于双向链表(Doubly LinkedList),还有一个prev指针指向前一个节点.与数组类似,搜索链表需要O(n)的时间复杂度,但是链表不能通过常数时间读取第k个数据.链表的优势在于能够以较?的效率在任意位

几何算法:点集合构造简单多边形

问题:给定平面中n个点所组成的集合,将它们连接起来形成一条简单的封闭路径.所谓简单路径,是指边与边无交叉. 如下图所示10个点组成的简单轮廓: 思路:取x坐标最大的点A(如果最大x坐标的点不止一个,则取Y坐标最小的点),依次计算A点与其余各点的连线与水平线之间夹角的正切值,然后按照正切值排序,依次连接排序后的各点即组成一个简单图形. 原理:其它所有点都在A点的左侧,所有夹角的范围为-Pi/2~Pi/2,单调递增函数. 举一个例子如下: 各点坐标与A点的角度斜率如下(已经排序好): x:426.1

【枚举算法Day1】20170529-2枚举算法专题练习

20170529-2枚举算法专题练习 青岛二中日期 序号 题目名称 输入文件名 输出文件名 时限 内存 算法 难度 分类 081113 1 最大矩形 rectangle.in rectangle.out 1s 256MB 枚举 1 02枚举 081031 2 回文 palin.in palin.out 1s 256MB 枚举.优化 1 02枚举 081008 3 问题的设置 problemsetter.in problemsetter.out 1s 256MB 排序+枚举 1 02枚举 0810

图的算法专题——最短路径

概要: Dijkstra算法 Bellman-Ford算法 SPFA算法 Floyd算法 1.Dijkstra算法用于解决单源最短路径问题,严格讲是无负权图的最短路径问题. 邻接矩阵版 1 const int maxv=1000; 2 const int INF=1000000000; 3 int n,G[maxv][maxv]; 4 int d[maxv]; //起点到各点的最短路径长度 5 bool vis[maxv]={false}; 6 7 void Dijkstra(int s){ /

最短路径算法专题1----弗洛伊德

由于最短路径算法我认为比较重要,所以分成几个专题来慢慢细化去磨它,不能一口气吃个胖子嘛. 首先在说算法之前,先说清楚什么叫做最短路径. 题目一般会给你一张图,然后告诉你很多地方,然后告诉你各个地方之间的路程有多远,要你求出,两点间的最短距离,注意,题目给出的两点间的距离未必是最短的,可能通过第三个点转换之后达到更短.实际其实也是这样的,有时候两个地方并没有直线的道路只有曲线的绕路. 算法的思路: 1.用二维数组列出所有的距离,达到不了的用最大距离表示,如9999999 2.循环数组上面的每一个点

括号匹配问题 -算法专题

算法数据结构面试分享 符号匹配问题 今天在帖子上看见有同学在问,如果一个字符串中包含大括号和小括号,我们该如何解决括号匹配问题.我们今天就一起看下这道题吧.按照我们之前的套路,按部就班来: 确保我们理解了问题,并且尝试一个例子,确认理解无误. 举个例子,这样的括号是匹配的, ().{}.({}), ({()}(){}), 而类似于{(.{,({)都是不匹配的. 想想你可以用什么方法解决问题,你会选择哪一种,为什么? 我们拿这个字符串为例,({()}(){}), 最后一个)匹配的是第一个(, 倒数

ACM&amp;OI 基础数学算法专题

[前言] 本人学习了一定时间的算法,主要精力都花在数学类的算法上面 而数学类的算法中,本人的大部分精力也花费在了数论算法上 此类算法相对抽象,证明过程比较复杂 网络上的博客有写得非常好的,但也有写得不明所以的 因此,本人特此开一个新的专题,专门负责讲解一些比较基础的数学类算法 但本人知识面也有限,部分算法也还未掌握.因此,希望本专题也能促进本人学习这些算法 下面做出对更新的一些规定: 基本上保持每日更新一贴 对标注(已完结)的贴子,表明本贴子已完结 对标注(正在更新)的贴子,表明正在更新本贴 对

KM算法专题

原文:http://972169909-qq-com.iteye.com/blog/1184514 题目地址:这里. 1)求图中所有环的总长度(环的长度不唯一)的最小值.当无法得到完备匹配时说明环不存在. 第三题:http://acm.hdu.edu.cn/showproblem.php?pid=1853 直接建图,注意有重边哦! if (-c > w[a][b])     w[a][b] = -c; 当木有完美匹配输出-1 第四题:http://acm.hdu.edu.cn/showprobl

最短路径算法专题2----Dijkstra

这个算法适用于求单源最短路径,从一点出发,到其余个点的最短路径. 算法要点: 1.用二维数组存放点到点的距离-----不能相互到达的点用MAX代替距离 2.用dis数组存放源点到任意其他一点的距离----dis[5]表示源点到5点的距离为dis[5]中的值 3.用book数组记录已经确定最小dis的点 4.用index和indexNumber存放估计值的点 5.从源点到这个点如果比中间加上估计值的点还要长,就松弛 算法模型: for(循环N次) { for(循环找到估计值点) { 估计值点是现在