首页 > 其他 > 详细

poj1269 Intersecting Lines

时间:2019-06-05 20:29:40      阅读:85      评论:0      收藏:0      [点我收藏+]

题目描述:

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

 

poj1269 Intersecting Lines

原文:https://www.cnblogs.com/LiGuanlin1124/p/10981489.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!