#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define INF 1 << 30
#define eps 1e-10
#define Vector Point
#define MAXD 310
/*=============================================*/
int dcmp(double x){
if(fabs(x) < eps)
return ;
else
return x < ? - : ;
}
struct Point{
double x;
double y;
Point(double a = ,double b = ): x(a),y(b) {};
friend bool operator < (Point p,Point q){
if(p.x == q.x)
return p.y < q.y;
else
return p.x < q.x;
}
friend Vector operator + (Point p,Point q){
return Vector(p.x + q.x , p.y + q.y);
}
friend Vector operator - (Point p,Point q){
return Vector(p.x - q.x , p.y - q.y);
}
friend Vector operator * (Point p,double t){
return Vector(p.x * t , p.y * t);
}
friend Vector operator / (Point p,double t){
return Vector(p.x / t , p.y / t);
}
friend bool operator == (Point p,Point q){
return dcmp(p.x - q.x) == && dcmp(p.y - q.y) == ;
}
};
double Dot(Vector p, Vector q){ //向量点积
return p.x * q.x + p.y * q.y;
}
double Length(Vector p){ //向量长度
return sqrt(p.x * p.x + p.y * p.y);
}
double Angle(Vector p ,Vector q){
return acos( Dot(p, q) /( Length(p) * Length(q) ) );
}
double Cross(Vector p,Vector q){
return p.x * q.y - p.y * q.x;
}
double Area2(Point a,Point b,Point c){
return Cross(a - b , c - b);
}
Vector Rotate(Vector p,double angle){
return Vector(p.x * cos(angle) - p.y * sin(angle), p.x * sin(angle) + p.y * cos(angle));
}
Vector Normal(Vector p){ //求法向量
double L = Length(p);
return Vector( - p.y / L , p.x / L);
}
Point GetLineCross(Point p,Vector v,Point q,Vector w){ //交点
Vector u = p - q;
double t = Cross(w,u) / Cross(v,w);
return p + v * t;
}
double Distance(Point p,Point a,Point b){ //点到射线的距离
Vector v1 = b - a;
Vector v2 = p - a;
return fabs(Cross(v1,v2)) / Length(v1);
}
double Distance2(Point p,Point a,Point b){
if(a == b)
return Length(p - a);
Vector v1 = b - a , v2 = p - a, v3 = p - b;
if(dcmp(Dot(v1,v2)) < )
return Length(v2);
else if(dcmp(Dot(v1,v3)) > )
return Length(v3);
else
return fabs(Cross(v1,v2))/ Length(v1);
}
Point GetLinePoint(Point p,Point a,Point b){ //点在线上的投影
Vector v = b - a;
return a + v * (Dot(v, p -a ) / Dot(v,v));
}
bool If_Cross(Point a1,Point a2,Point b1,Point 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) < && dcmp(c3) * dcmp(c4) < ;
}
bool If_InLine(Point p,Point a1,Point a2){
return dcmp(Cross(a1 - p , a2 - p)) == && dcmp(Dot(a1 - p , a2 - p)) < ;
}