You are not logged in. Please login at www.codechef.com to post your questions!

×

Medium

# Problem:

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

# Explanation:

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.

# Solution:

Author's solution can be found here.

asked 13 May '17, 19:27

163
accept rate: 0%

19.7k350498541

 1 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 ?? answered 30 May '17, 16:56 4★am10 55●6 accept rate: 0%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×2,575
×637
×160
×61
×1

question asked: 13 May '17, 19:27

question was seen: 619 times

last updated: 01 Jun '17, 17:53