• 计算几何大佬板子


    struct P {
        double x,y;
        P() {}
        P(double x, double y) {
            this->x = x;
            this->y = y;
        }
        P operator + (const P &c) const {
            return P(x + c.x, y + c.y);
        }
        P operator - (const P &c) const {
            return P(x - c.x, y - c.y);
        }
        P operator * (const db &c) const {
            return P(x * c, y * c);
        }
        P operator / (const db &c) const {
            return P(x / c, y / c);
        }
    };
    
    int n;
    P p[N];
    bool f[N][N];
    ll dp[N][N];
    
    P read() {
        double x, y;scanf("%lf%lf",&x,&y);
        return P(x, y);
    }
    
    void print(P p) {
        printf("%lf %lf
    ",p.x,p.y);
    }
    
    int sign(double x) {
        return (x>eps)-(x<-eps);
    }
    db dot(P a, P b) {
        return x(a) * x(b) + y(a) * y(b);
    }
    double cross(P a, P b) {
        return x(a) * y(b) - x(b) * y(a);
    }
        
    //判断线段是否规范相交(交点不在任一个端点上)
    bool isSS0(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 sign(c1) * sign(c2) < 0 && sign(c3) * sign(c4) < 0;
    }
    //判断线段是否不规范相交
    bool isSS1(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 sign(max(x(a1), x(a2)) - min(x(b1), x(b2))) >= 0 &&
               sign(max(x(b1), x(b2)) - min(x(a1), x(a2))) >= 0 &&
               sign(max(y(a1), y(a2)) - min(y(b1), y(b2))) >= 0 &&
               sign(max(y(b1), y(b2)) - min(y(a1), y(a2))) >= 0 &&
               sign(c1) * sign(c2) <= 0 && sign(c3) * sign(c4) <= 0;
    }
    //判断点是否在线段上(不包括端点)
    bool onS0(P p, P a, P b) {
        return sign(cross(p - a, b - a)) == 0 && sign(dot(p - a, p - b)) < 0;
    }
    //判断点是否在线段上(包括端点)
    bool onS1(P p, P a, P b) {
        return sign(cross(p - a, b - a)) == 0 && sign(dot(p - a, p - b)) <= 0;
    }
    //判断点和多边形关系 边上-1 外0 内1
    int Pinploy(P o, P *p, int n) {
        int res = 0;
        rep(i, 0, n) {
            P u = p[i], v = p[(i + 1) % n];
            if(onS1(o, u, v)) return -1;
            int k = sign(cross(v - u, o - u));
            int d1 = sign(y(u) - y(o));
            int d2 = sign(y(v) - y(o));
            if(k > 0 && d1 <= 0 && d2 > 0) ++res;
            if(k < 0 && d2 <= 0 && d1 > 0) --res;
        }
        return res != 0;
    }
  • 相关阅读:
    js里面的 InttoStr 和 StrtoInt
    预编译知识 (转载记录)
    C语言操作内存
    C语言操作文件
    C语言
    如何调试shell脚本
    设计模式-装饰者模式
    自己动手制作一个模版解析
    设计模式-单例模式
    http中关于缓存的那些header信息
  • 原文地址:https://www.cnblogs.com/chinacwj/p/8671143.html
Copyright © 2020-2023  润新知