• poj3304 Segments【计算几何】


    最近开始刷计算几何了 公式好多完全不会

    数学不行 几何不行 记忆力不行 当机

    查的题解 就当复习吧 这套专题拿来熟悉一下计算几何模板

    #include <iostream>
    #include<stdio.h>
    #include<math.h>
    
    using namespace std;
    
    const double eps = 1e-8;
    int sgn(double x)//处理精度
    {
        if(fabs(x) < eps) return 0;
        if(x < 0) return -1;
        return 1;
    }
    struct point{
        double x, y;
        point(){}
        point(double xx, double yy):x(xx), y(yy){}
        point operator -(const point &a) const{
            return point(x - a.x, y - a.y);
        }
        double operator ^(const point &a) const{
            return x * a.y - y * a.x;
        }
        double operator *(const point &a) const{
            return x * a.x + y * a.y;
        }
    };
    struct line{
        point s, e;
        line(){}
        line(point ss, point ee):s(ss), e(ee){}
    };
    
    double xmult(point p0, point p1, point p2)//判断p0是否在p1-p2直线上
    {
        return (p1 - p0) ^ (p2 - p0);
    }
    bool seg_line(line a, line b)
    {
        return sgn(xmult(b.s, a.s, a.e) * sgn(xmult(b.e, a.s, a.e))) <= 0;//线段b的两个端点在直线a的两端
    }
    
    double dist(point a, point b)
    {
        return sqrt((b - a) * (b - a));
    }
    
    const int maxn = 110;
    line ll[maxn];
    bool check(line a, int n)
    {
        if(sgn(dist(a.s, a.e))== 0) return false;
        for(int i = 0; i < n; i++){
            if(seg_line(a, ll[i]) == 0)
                return false;
        }
        return true;
    }
    
    int main()
    {
        int n, t;
        cin>>t;
        while(t--){
            cin>>n;
            double x1, x2, y1, y2;
            for(int i = 0; i < n; i++){
                cin>>x1>>y1>>x2>>y2;
                ll[i] = line(point(x1, y1), point(x2, y2));
            }
            int flag = 0;
            for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                    if(check(line(ll[i].s, ll[j].s), n) || check(line(ll[i].s, ll[j].e), n)||
                       check(line(ll[i].e, ll[j].s), n) || check(line(ll[i].e, ll[j].e), n)){
                            flag = true;//找到了一条直线可以和所有的线段相交
                            break;
                       }
                }
            }
            printf("%s
    ", flag ? "Yes!" : "No!");
        }
        return 0;
    }



  • 相关阅读:
    mac os 虚拟机安装
    linux 安装Swagger(swagger-editor , swagger-ui)
    Centos6.5安装pip命令以及中途遇到的问题
    CentOS6.5 下将 Python2.6.6 升级到Python3.5
    要么忙着活,要么忙着死
    在CentOS6.8下安装Docker
    Elasticsearch 不同的搜索类型之间的区别
    解决 Python shell 中 Delete/Backspace 键乱码问题
    Java 反射机制
    Spring Security Oauth2 的配置
  • 原文地址:https://www.cnblogs.com/wyboooo/p/9643416.html
Copyright © 2020-2023  润新知