Veshy is struggling in math class so he asks you for help (again). You are given two lines each defined by a pair of distinct points, and , . You are to find if the two lines are parallel, coincident, or intersecting.
Input Specification
The input will consist of two lines.
The first line of input will consist of four space-separated integers in the following order: , , , , the coordinates of the two points that define the first line.
The second line of input is the same format as the first line containing the coordinates of the points defining the second line.
In all cases, .
Output Specification
If the lines are coincident, output coincident
.
If the lines are parallel but not coincident, output parallel
.
If the lines intersect, output the point of intersection in the form x y
.
Output your answer to 6 decimal places.
Your answer will be considered correct if its absolute or relative error does not exceed .
Sample Input 1
0 0 1 1
-1 -1 -2 -2
Sample Output 1
coincident
Sample Input 2
0 0 1 2
2 0 3 2
Sample Output 2
parallel
Sample Input 3
0 0 0 4
-2 6 2 6
Sample Output 3
0.000000 6.000000
Comments
This comment is hidden due to too much negative feedback. Show it anyway.
You should refer to the DMOJ discord for help with your code. Also, I'm also not completely sure if you handled the undefined slope case properly.
Okay
Is it possible to AC with a solution that finds the slope and y-intercept and handles exception cases separately?
You can't find slope without handling exception cases. What if you get the slope ?
Pretty much I am wondering if there is a correct solution that solves the problem using y = mx + b form when neither line has an undefined slope (the two x-values are the same), and handles the case where either one or both of the lines have an undefined slope separately. Because this is the way I did it and I am wrong answering on case #52.
I was also getting WA on case #52 and using slope-intercept form, even after trying to handle all edge cases.
Floating point division is bad. Try to avoid it as much as possible in your code.
Can you avoid this by merging the final calculation into one big equation and not storing values for intermediate steps.
There is a solution that solves this problem using slope y-intercept form, although it is more annoying to code than standard form. If you having trouble with case 52, I recommend that wherever you compare two doubles (using == or !=), to use epsilons to check if they are the same instead. Floating point division is accurate enough for the small range of -250 to 250.
Test case #52 is a rounding error question. Adding margin for error works too.
What do you mean by adding margin for error?
Instead of comparing floats directly, you can do something like
So 7.00000001 would be considered equal to 7.0
That works, thank you!
Note: Make sure
-0.000000
is not in your output.Edit: I made a mistake.
It shouldn't matter, my submission produces
-0.000000
and still passes.