struct point {
double x,y;
point(double x=0,double y=0):x(x),y(y) {}
}g[1000000],yuan;
typedef point vec;
const double eps=1e-8;
const double pi=acos(-1.0);
bool cmp(point a,point b) {
if(fabs(a.x-b.x)<=eps) return a.y<b.y;
return a.x<b.x;
}
vec operator -(point a,point b) {
return vec(a.x-b.x,a.y-b.y);
}
vec operator +(point a,point b) {
return vec(a.x+b.x,a.y+b.y);
}
vec operator *(point a,double t) {
return vec(a.x*t,a.y*t);
}
vec operator /(point a,double t) {
return vec(a.x/t,a.y/t);
}
bool operator < (const point &a,const point &b) {
return a.y<b.y || (fabs(a.y-b.y)<=eps && a.x<b.x);
}
bool operator == (const point &a,const point &b) {
if(fabs(a.x-b.x)<=eps && fabs(a.y-b.y)<=eps)
return true;
return false;
}
int dcmp(double x) {
if(fabs(x)<=eps) return 0;
return x<0?-1:1;
}
double cross(vec a,vec b) {///叉积
return a.x*b.y-a.y*b.x;
}
double dot(vec a,vec b) {///点积
return a.x*b.x+a.y*b.y;
}
double disn(point a,point b) {
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
/*两点之间的距离*/
}
double lentgh(vec a){///向量长度
return sqrt(dot(a,a));
}
double vec_angle(vec a,vec b){ ///两向量夹角
return acos(dot(a,b)/lentgh(a)/lentgh(b));
}
double distance(point p,point a,point b){
vec v1=b-a;
vec v2=p-a;
return fabs(cross(v1,v2))/lentgh(v1);
/* 点到直线的距离
若不取绝对值 表示有向距离
*/
}
double distancetoseg(point p,point a,point b){
if(a==b) return lentgh(p-a);
vec v1=b-a;
vec v2=p-a;
vec v3=p-b;
if(dcmp(dot(v1,v2))<0)
return lentgh(v2);
else if(dcmp(dot(v1,v3))>0)
return lentgh(v3);
else
return fabs(cross(v1,v2))/lentgh(v1);
/*点到线段的距离*/
}