zoukankan      html  css  js  c++  java
  • poj1269 Intersecting Lines

    题目描述:

    vjudge

    POJ

    题解:

    直线判交没啥好说的……

    (不要用g++,一定要用c++)

    代码:

    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    const double eps = 1e-8;
    int dcmp(double x)
    {
        if(fabs(x)<=eps)return 0;
        return x>0?1:-1;
    }
    struct Point
    {
        double x,y;
        Point(){}
        Point(double x,double y):x(x),y(y){}
        Point operator +(const Point&a)const{return Point(x+a.x,y+a.y);}
        Point operator -(const Point&a)const{return Point(x-a.x,y-a.y);}
        Point operator *(const double&a)const{return Point(x*a,y*a);}
        double operator ^(const Point&a)const{return x*a.y-y*a.x;}
    }a,b,c,d;
    typedef Point Vector;
    struct Line
    {
        Point p;
        Vector v;
        Line(){}
        Line(Point p,Vector v):p(p),v(v){}
    }s1,s2;
    int n;
    void work()
    {
        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);
        s1 = Line(a,b-a),s2 = Line(c,d-c);
        if(!dcmp(s1.v^s2.v))
        {
            if(!dcmp(s1.v^(s2.p-s1.p)))puts("LINE");
            else puts("NONE");
        }else
        {
            double t = fabs(((s2.p-s1.p)^s2.v)/(s1.v^s2.v));
            Point now = s1.p+s1.v*t;
            printf("POINT %.2lf %.2lf
    ",now.x,now.y);
        }
    }
    int main()
    {
        puts("INTERSECTING LINES OUTPUT");
        scanf("%d",&n);
        while(n--)work();
        puts("END OF OUTPUT");
        return 0;
    }
    View Code
  • 相关阅读:
    java单例类
    java构造方法-this关键字的用法
    java封装
    Bean的装配方式
    scope的范围
    Bean实例化(三种方法)
    依赖注入
    建立Spring项目的基础
    Androids中数据库的使用SQLite
    SharedPreferences
  • 原文地址:https://www.cnblogs.com/LiGuanlin1124/p/10981489.html
Copyright © 2011-2022 走看看