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

 

转载于:https://www.cnblogs.com/LiGuanlin1124/p/10981489.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值