Hust oj 1104 Leyni, LOLI and Line(线段相交)

Leyni, LOLI and Line
Time Limit: 1000 MSMemory Limit: 65536 K
Total Submit: 227(84 users)Total Accepted: 118(79 users)Rating: Special Judge: No
Description

Professor Leyni likes to help LOLIs with their math.
This time, Leyni meets several LOLIs in the classroom and gets several problems about "Intersecting Lines".
The LOLIs want to know how and where two lines intersect.Leyni asks you to help him to answer.

Input

There are multiple test cases. The first line of input is an integer T indicating the number of test cases. Then T test cases follow.
For each test case:
Line 1. This line contains eight integers. These integers represent the coordinates of four points on the plane in the order x1y1x2y2x3y3x4y4. Thus each of these input lines represents two lines on the plane: the line through (x1,y1) and (x2,y2) and the line through (x3,y3) and (x4,y4). The point (x1,y1) is always distinct from (x2,y2). Likewise with (x3,y3) and (x4,y4).
All numbers required by this problem will be in the range [-1000, 1000].

Output

For each test case:
Line 1.If there is no intersection, output "NONE". If they are the same line, output "LINE". Otherwise output the x and y coordinates of the point, correct to two decimal places as the sample output.

Sample Input

5
0 0 4 4 0 4 4 0
5 0 7 6 1 0 2 3
5 0 7 6 3 -6 4 -3
2 0 2 27 1 5 18 5
0 3 4 0 1 2 2 5

Sample Output

POINT 2.00 2.00
NONE
LINE
POINT 2.00 5.00
POINT 1.07 2.20

注意与X轴垂直是没有斜率,需要特判

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;

int t;
double x1,x2,x3,x4,y1,y2,y3,y4;
double k1,k2,b1,b2;

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
        k1 = (y2-y1) / (x2-x1);
        b1 = y1 - k1 * x1;
        k2 = (y4-y3) / (x4-x3);
        b2 = y3 - k2 * x3;
        if(k1 == k2)
        {
            if(b1 == b2)
                printf("LINE\n");
            else
                printf("NONE\n");
        }
        else if(x1 == x2 && x3 == x4)
        {
            if(x1 == x3)
                printf("LINE\n");
            else
                printf("NONE\n");
        }
        else if(x1 == x2)
        {
           printf("POINT %.2lf %.2lf\n",x1,k2*x1+b2);
        }
         else if(x3 == x4)
        {
           printf("POINT %.2lf %.2lf\n",x3,k1*x3+b1);
        }
        else
        {
            double x = (b2 - b1) / (k1 - k2);
            printf("POINT %.2lf %.2lf\n",x,k1*x+b1);
        }
    }
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值