BITMASK4 - Editorial

Problem Link:





We need to find the biggest set of parallel lines from the given lines.


Equation of line is given by ax+by+c=0 -eq(1).
where a,b,c are coefficients.
And the slope-intercept form of the line is given by y = mx + C -eq(2).
where m is the slope of line and C is the y-intercept.
Comparing eq(1) and eq(2), we get:
m = -a/b and C = -c/b

Now for two lines to be parallel, they must have the same slope and different y-intercept. Different y-intercept because if two lines have same slope and y-intercept then both lines are same and they will meet at every point.

So we just need to make different sets of parallel lines according to their slopes and then find the length of the largest set.
Also, we need to check for the case where b is 0. To handle the divide by zero exception. In that case, we can assign m to a very large number and C to -c/a.
One way to do this is to use a map of slope and set of lines having that slope. The slope with the largest set of lines will be the required answer.


Author’s solution can be found here.

In this problem why we are not having Precision error due to floating point arithmetic .As in your solution you are taking m = -a/b and y intercept = -c/a.can you explain ??

1 Like