• POJ 1269 Intersecting Lines(求直线交点)


    http://poj.org/problem?id=1269

    求交点见zhhx课件

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    const double eps=1e-8;
    const int maxn=100004;
    int dcmp(double x) {
        if(fabs(x) < eps) return 0;
        return x < 0 ? -1 : 1;
    }
    #define Point Vector
    struct Vector{
        double x,y;
        Vector(double x=0,double y=0):x(x),y(y){};
        Vector operator + (const Vector &A) const{
            return Vector(x+A.x,y+A.y);
        }
        Vector operator - (const Vector &A) const{
            return Vector(x-A.x,y-A.y);
        }
        Vector operator * (const double &A) const{
            return Vector(x*A,y*A);
        }
        Vector operator / (const double &A) const{
            return Vector(x/A,y/A);
        }
        bool operator == (const Vector &A) const{
            return dcmp(x-A.x)==0&&dcmp(y-A.y)==0;
        }
    };
    struct Line{
        Point p1,p2;
        Line(){};
        Line(Point p1,Point p2):p1(p1),p2(p2){}
    }li[maxn];
    bool operator < (Line l1,Line l2){
        if(l1.p1.x==l2.p1.x) return l1.p1.y<l2.p1.y;
        else return l1.p1.x<l2.p1.x;
    }
    int ans[maxn],num[maxn],n,m;
    double U,L,R,D;
    double PolarAngle(Vector A){
        return atan2(A.y,A.x);
    }
    Vector rotate(Vector &A,double a){
        return A=Vector(A.x*cos(a)-A.y*sin(a),A.x*sin(a)+A.y*cos(a));
    }
    double Dot(Vector A,Vector B){
        return A.x*B.x+A.y*B.y;
    }
    double Cross(Vector A,Vector B){
        return A.x*B.y-A.y*B.x;
    }
    Point GLI(Point P,Vector v,Point Q,Vector w){
        Vector u=P-Q;
        double t=Cross(w,u)/Cross(v,w);
        return P+v*t;
    }
    int main(){
        scanf("%d",&n);
        printf("INTERSECTING LINES OUTPUT
    ");
        for(int i=1;i<=n;i++){
            Point a,b,c,d;
            scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y);
            Vector p1,p2;
            p1=b-a,p2=d-c;
            if(dcmp(Cross(p1,p2))==0){
                if(dcmp(Cross(c-a,p1))==0&&dcmp(Cross(d-a,p1))==0) printf("LINE
    ");
                else printf("NONE
    ");
                continue;
            }
            Point p=GLI(a,p1,c,p2);
            printf("POINT %.2lf %.2lf
    ",p.x,p.y);
        }
        printf("END OF OUTPUT");
    }
  • 相关阅读:
    重置 VCSA 6.7 root密码和SSO密码
    在AD中导出所有用户
    博科光纤交换机300
    C#复制和移动文件夹
    在控制台程序中使用IHttpClientFactory
    C#:解决JSON序列化时时间格式带“T”的问题
    .Net Core:解决WebAPI中返回时间格式带T的问题
    Apache Ranger安装部署
    windows批处理 打开exe后关闭cmd
    Wechat占用1099端口
  • 原文地址:https://www.cnblogs.com/wifimonster/p/10323956.html
Copyright © 2020-2023  润新知