几何常用

叉乘,点乘,用结构体存cos^2

int n, ans = 1, X[N], Y[N];

struct node
{
    double x,y;
    node(): node(0,0){}
    node(double x,double y):x(x),y(y){}
    bool operator < (const node& r)
    {
        return (double)x*r.y<(double)y*r.x;
    }
    bool operator == (const node& r)
    {
        return (double)x*r.y==(double)y*r.x;
    }
};

int Cross(int lhs, int rhs)
{
    return X[lhs] * Y[rhs] - X[rhs] * Y[lhs];
}

int Dot(int lhs, int rhs)
{
    return X[lhs] * X[rhs] + Y[lhs] * Y[rhs];
}

double Dis2(int lhs, int rhs)
{
    double dx = X[lhs] - X[rhs], dy = Y[lhs] - Y[rhs];
    return dx * dx + dy * dy;
}

int Sgn(int x)
{
    if (x > 0) return 1;
    if (x < 0) return -1;
    return 0;
}

node ar[N];

node cos2(ll x, ll y)
{
    ll a2=Dis2(0,x),b2=Dis2(x,y),c2=Dis2(0,y);
    int sgn=Sgn(b2+c2-a2);
    return node((double)1*sgn*(b2 + c2 - a2) * (b2 + c2 - a2), (double)4 * b2 * c2);
}

 三角形面积:The formula for the area of triangle

|Ax(ByCy)+Bx(CyAy)+Cx(AyBy)|/2

原文地址:https://www.cnblogs.com/dealer/p/13320733.html