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

来源:互联网 发布:淘宝账号能注销掉吗 编辑:程序博客网 时间:2024/06/05 09:44
Leyni, LOLI and LineTime Limit: 1000 MSMemory Limit: 65536 KTotal Submit: 227(84 users)Total Accepted: 118(79 users)Rating: Special Judge: NoDescription

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
原创粉丝点击