poj 1269 Intersecting Lines 【直线相交】



点击打开链接


题意:


         给你两个条直线,判断两条直线的关系,

         如果相交于一点,输出POINT 和该点坐标,

         如果重合输出 LINE

         如果平行输出 NONE


题解:


        赤裸裸的判断两线相交,,



#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<cmath>
#define x first
#define y second
using namespace std;
const double eps=1e-8;
const double PI=acos(-1.0);
const int maxn=105;
int sgn(double x){
    if(fabs(x)<eps) return 0;
    if(x<0) return -1;
    return 1;
}
struct Point{
    double x,y;
    Point(){}
    Point(double _x,double _y){
        x=_x;y=_y;
    }
    Point operator -(const Point &b)const{
        return Point(x-b.x,y-b.y);
    }
    double operator ^ (const Point &b)const{
        return x*b.y - y*b.x;
    }
};
struct Line{
    Point s,e;
    Line(){}
    Line(Point _s,Point _e){
        s=_s;e=_e;
    }
    pair<int,Point> operator &(const Line &b)const{
        Point res=s;
        if(sgn((s-e)^(b.s-b.e))==0){
            if(sgn((s-b.e)^(b.s-b.e))==0)
                return make_pair(0,res);
            return make_pair(1,res);
        }
        double tt=((s-b.s)^(b.s-b.e))/((s-e)^(b.s-b.e));
        res.x+=(e.x-s.x)*tt;
        res.y+=(e.y-s.y)*tt;
        return make_pair(2,res);
    }
};
Point p1,p2,p3,p4;
Line t1,t2;
int main(){
    int t,n,cnt;
    double x1,x2,x3,x4,y1,y2,y3,y4;
    scanf("%d",&t);
    puts("INTERSECTING LINES OUTPUT");
    while(t--){
        scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
        p1={x1,y1};p2={x2,y2};
        p3={x3,y3};p4={x4,y4};
        t1={p1,p2};t2={p3,p4};
        pair<int,Point>ans=t1&t2;
        if(ans.x==0) puts("LINE");
        else if(ans.x==1) puts("NONE");
        else {
            printf("POINT %.2f %.2f\n",ans.y.x,ans.y.y);
        }
    }
    puts("END OF OUTPUT");
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值