POJ1269 直线相交

版子 http://blog.csdn.net/acm_zl/article/details/9471451

    #include <iostream>  
    #include <cstdio>  
    #include <string>  
    #include <string.h>  
    #include <map>  
    #include <vector>  
    #include <cstdlib>  
    #include <cmath>  
    #include <algorithm>  
    #include <queue>  
    #include <set>  
    #include <stack>  
    using namespace std;  
      
    int main()  
    {  
        int t;  
        double x1,y1,x2,y2,x3,y3,x4,y4;  
        scanf("%d", &t);  
        printf("INTERSECTING LINES OUTPUT\n");  
        while(t--)  
        {  
            scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);  
            if(x1==x2 && x3==x4)//两直线都没有斜率  
            {  
                if(x3==x1)  
                    printf("LINE\n");  
                else  
                    printf("NONE\n");  
            }  
            else if(x1==x2 && x3!=x4)//有一条直线斜率存在  
            {  
                double k = (y4-y3)*1.0/(x4-x3);  
                double b = y3-(k*x3);  
                double ansx = x1;  
                double ansy = k*x1+b;  
                printf("POINT %.2lf %.2lf\n", ansx, ansy);  
            }  
            else if(x1!=x2 && x3==x4)//有一条直线斜率存在  
            {  
                double k = (y2-y1)*1.0/(x2-x1);  
                double b = y2-(k*x2);  
                double ansx = x3;  
                double ansy = k*x3+b;  
                printf("POINT %.2lf %.2lf\n", ansx, ansy);  
            }  
            else //两条直线斜率都存在  
            {  
                double k1 = (y2-y1)*1.0/(x2-x1);  
                double b1 = y2-(k1*x2);  
                double k2 = (y4-y3)*1.0/(x4-x3);  
                double b2 = y3-(k2*x3);  
                if(k1==k2)  
                {  
                    if(b1==b2)  
                        printf("LINE\n");  
                    else  
                        printf("NONE\n");  
                }  
                else  
                {  
                    double ansx = (b1-b2)*1.0/(k2-k1);  
                    double ansy = k1*ansx + b1;  
                    printf("POINT %.2lf %.2lf\n", ansx, ansy);  
                }  
            }  
        }  
        printf("END OF OUTPUT\n");  
        return 0;  
    }  

 

转载于:https://www.cnblogs.com/nj-czy/p/5867614.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值