## DMOPC '19 Contest 6 P1 - Grade 9 Math

View as PDF

Points: 7
Time limit: 2.0s
Memory limit: 256M

Author:
Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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

• commented on Aug. 6, 2020, 4:24 p.m. edit 6

This comment is hidden due to too much negative feedback. Click here to view it.

• commented on Aug. 6, 2020, 5:20 p.m.

You should refer to the DMOJ slack for help with your code. Also, I'm also not completely sure if you handled the undefined slope case properly.

• commented on Aug. 8, 2020, 3:22 p.m.

Okay

• commented on April 1, 2020, 2:09 p.m.

Hey can anyone tell me what is wrong with my code. I thought I had everything right but I WA on case 1

• commented on March 30, 2020, 12:40 p.m.

Is it possible to AC with a solution that finds the slope and y-intercept and handles exception cases separately?

• commented on March 30, 2020, 1:18 p.m.

You can't find slope without handling exception cases. What if you get the slope ?

• commented on March 30, 2020, 4:12 p.m.

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.

• commented on March 30, 2020, 5:11 p.m. edited

I was also getting WA on case #52 and using slope-intercept form, even after trying to handle all edge cases.

• commented on March 30, 2020, 6:31 p.m.

Floating point division is bad. Try to avoid it as much as possible in your code.

• commented on March 30, 2020, 10:21 p.m.

Can you avoid this by merging the final calculation into one big equation and not storing values for intermediate steps.

• commented on March 31, 2020, 12:17 p.m. edited

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.

• commented on April 1, 2020, 2:08 a.m.

Test case #52 is a rounding error question. Adding margin for error works too.

• commented on April 1, 2020, 5:00 p.m.

What do you mean by adding margin for error?

• commented on April 1, 2020, 7:01 p.m. edited

Instead of comparing floats directly, you can do something like

if (abs(float1 - float2) < 0.0001)

So 7.00000001 would be considered equal to 7.0

• commented on April 1, 2020, 7:29 p.m.

That works, thank you!

• commented on March 30, 2020, 11:18 a.m. edited

Note: Make sure -0.000000 is not in your output.

It shouldn't matter, my submission produces -0.000000 and still passes.