1. Check for the lines that are parallel to Y axis (slope = inf)
2. Check for the lines that are parallel to Y axis and have the same X co-ord
3. Check for the liens that have the same slope
- a. Whether they meet on line
b. Whether they meet on point
Moderator: Board moderators
Code: Select all
#include<stdio.h>
#include<math.h>
int main(void)
{
register long double x1,y1,x2,y2,x3,y3,x4,y4,a1,b1,c1,a2,b2,c2,l,xh,yh,x,y;
register int test;
scanf("%d",&test);
printf("INTERSECTING LINES OUTPUT\n");
while(test--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
a1=y1-y2;
b1=x2-x1;
c1=y1*(x1-x2)-x1*(y1-y2);
a2=y3-y4;
b2=x4-x3;
c2=y3*(x3-x4)-x3*(y3-y4);
if((c1==0 && c2==0))
{
if(a2!=0 && b2!=0 )
{
if((fabs((a1/a2)-(b1/b2)))>0.00)
{
printf("POINT 0.00 0.00\n");
continue;
}
else
{
printf("LINE\n");
continue;
}
}
else
{
if(a1!=0 && a2==0.0)
{
printf("POINT 0.00 0.00\n");
continue;
}
if(b1!=0 && b2==0.0)
{
printf("POINT 0.00 0.00\n");
continue;
}
}
}
if(a1==0 && a2==0)
{
if(fabs((c1/b1)-(c2/b2))<0.000000000000000000000000001)
{
printf("LINE\n");
}
else
{
printf("NONE\n");
}
continue;
}
if(b1==0 && b2==0)
{
if(fabs((c1/a1)-(c2/a2))<0.0000000000000000000000000001)
{
printf("LINE\n");
}
else
{
printf("NONE\n");
}
continue;
}
if(a1==0 && c1==0)
{
y=0;
x=-c2/a2;
printf("POINT %.2lf %.2lf\n",x,y);
continue;
}
if(a2==0 && c2==0)
{
y=0;
x=-c1/a1;
printf("POINT %.2lf %.2lf\n",x,y);
continue;
}
if(b1==0 && c1==0)
{
x=0;
y=-c2/b2;
printf("POINT %.2lf %.2lf\n",x,y);
continue;
}
if(b2==0 && c2==0)
{
x=0;
y=-c1/b1;
printf("POINT %.2lf %.2lf\n",x,y);
continue;
}
if(b1!=0.0 && b2!=0.0 && fabs((a1/b1)-(a2/b2))<.00000000000000000000000000001)
{
if(fabs((a1/a2)-(c1/c2))<.0000000000000000000000000000001 && fabs((b1/b2)-(c1/c2))<.0000000000000000000000000000001)
{
printf("LINE\n");
}
else
{
printf("NONE\n");
}
}
else
{
l=a2*b1 - a1*b2;
xh= b2*c1 - b1*c2;
yh= a1*c2 - a2*c1;
x= xh/l;
y= yh/l;
printf("POINT %.2lf %.2lf\n",x,y);
}
}
printf("END OF OUTPUT\n");
return 0;
}
Code: Select all
//CODE has removed after getting AC!!
Code: Select all
if(fabs((a1/a2)-(b1/b2))<esp
Code: Select all
if(fabs((a1*b2)-(b1*a2))<esp
& after correction it show-Your program has not solved the problem. It ran during 0.002 seconds.
Your program has not solved the problem. It ran during 0.000 seconds.
Code: Select all
if((a1*b2-a2*b1)==0)
Look for a bug in this part of your code - why did you use a1*b2-a2*b1 twice.Code: Select all
if(fabs(a1*b2-a2*b1)<eps) { if(fabs(a1*b2-a2*b1)<eps && fabs(b1*c2-b2*c1)<eps) printf("LINE\n");
That shouldn't matter because inputs are all integers, and so all computations will be exact.Jan wrote:Is this check valid? or you should use eps?Code: Select all
if((a1*b2-a2*b1)==0)
Your code fails on the following test:Oronno wrote:I become tired getting WA from this problem . I test all the SAMPLE I/o from forum, my program show Correct Answer. But whats happen to UVA???
plz help....if can give some sample I/O for which my code show WA
Code: Select all
1
1 0 1 1 2 0 2 1