Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 5442 | Accepted: 2567 |
Description
Your program will repeatedly read in four points that define two lines in the x-y plane and determine how and where the lines intersect. All numbers required by this problem will be reasonable, say between -1000 and 1000.
Input
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
INTERSECTING LINES OUTPUT POINT 2.00 2.00 NONE LINE POINT 2.00 5.00 POINT 1.07 2.20 END OF OUTPUT
#include<stdio.h>
int main()
{
int t;
double x1,y1,x2,y2,x3,y3,x4,y4,x,y,k1,k2,b1,b2;
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(x1==x3)
printf("LINE\n");
else
printf("NONE\n");
}
else if(x1==x2&&x3!=x4)//其中一条斜率不存在
{
k1=(y4-y3)*1.0/(x4-x3);
b1=y3-k1*x3;
x=x1;
y=k1*x+b1;
printf("POINT %.2f %.2f\n",x,y);
}
else if(x1!=x2&&x3==x4)//其中一条斜率不存在
{
k1=(y2-y1)*1.0/(x2-x1);
b1=y1-k1*x1;
x=x3;
y=k1*x+b1;
printf("POINT %.2f %.2f\n",x,y);
}
else if(x1!=x2&&x3!=x4)//两条斜率都存在
{
k1=(y2-y1)*1.0/(x2-x1);
b1=y1-k1*x1;
k2=(y4-y3)*1.0/(x4-x3);
b2=y3-k2*x3;
if(k1==k2)
{
if(b1==b2)
printf("LINE\n");
else
printf("NONE\n");
}
else
{
x=(b1-b2)*1.0/(k2-k1);
y=k1*x+b1;
printf("POINT %.2f %.2f\n",x,y);
}
}
}
printf("END OF OUTPUT\n");
return 0;
}