• 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");
    }
  • 相关阅读:
    Linux学习--------二
    Linux学习--------一
    PHP的回调函数
    妙用PHP函数处理数组
    MySQL错误码大全
    godoc使用方法介绍
    JS处理数据四舍五入(tofixed与round的区别详解)
    laravel手动数组分页
    PhpStorm+Xdebug配置单步调试PHP
    设计函数时,要考虑的因素
  • 原文地址:https://www.cnblogs.com/wifimonster/p/10323956.html
Copyright © 2020-2023  润新知