#include #include #include #include #include using namespace std; struct Point { double x,y; Point(double x=0,double y=0):x(x),y(y){} }; typedef Point Vector; inline Vector operator+(const Vector &A,const Vector &B) { return Vector(A.x+B.x,A.y+B.y); } inline Vector operator-(const Point &a,const Point &b) { return Vector(a.x-b.x,a.y-b.y); } inline Vector operator*(const Vector &A,double p) { return Vector(A.x*p,A.y*p); } inline Vector operator/(const Vector &A,double p) { return Vector(A.x/p,A.y/p); } inline bool operator<(const Point &a,const Point &b) { return a.x0?x:-x)0?1:-1); } inline bool operator==(const Point &a,const Point &b) { return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0; } inline double Dot(const Vector &A,const Vector &B) { return A.x*B.x+A.y*B.y; } inline double Length(const Vector &A) { return sqrt(Dot(A,A)); } inline double Cross(const Vector &A,const Vector &B) { return A.x*B.y-A.y*B.x; } inline Vector Normal(const Vector &A) { double L=Length(A); return Vector(-A.y/L,A.x/L); } struct Line { Point P; Vector v; double ang; Line(Point P=Point(),Vector v=Vector()):P(P),v(v) { ang=atan2(v.y,v.x); } inline bool operator<(const Line &L) const { return ang0; } Point GetLineIntersection(const Line &a,const Line &b) { Vector 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,Point *poly) { sort(L,L+n); int first,last; Point *p=new Point[n]; Line *q=new Line[n]; q[first=last=0]=L[0]; for(int i=1;i1e-6) { double mid=(left+right)/2; for(int i=0;i