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\n",now.x,now.y);
    }
}
int main()
{
    puts("INTERSECTING LINES OUTPUT");
    scanf("%d",&n);
    while(n--)work();
    puts("END OF OUTPUT");
    return 0;
}
View Code

 

posted @ 2019-06-05 19:31  LiGuanlin  阅读(405)  评论(0编辑  收藏  举报