Game of Lines
InterviewTime limit1sMemory limit128 MB
Given N distinct lattice points, count how many distinct slopes the lines through pairs of points can have.
- Level
Easy3 of 10
- Topics
- Hash map, Math, Geometry, Implementation
- Solved
- No attempts yet
Problem
Farmer John has challenged Bessie to the following game. FJ has a board with () distinct lattice points marked on it. Point has the integer coordinates and ().
Bessie scores a point by choosing two of the marked points and drawing the straight line through them. However, she may not draw a line if she has already drawn another line parallel to it. Two lines are parallel when they have the same slope, and two vertical lines are also considered parallel to each other.
Help Bessie find the maximum number of lines she can draw such that no two of them are parallel. In other words, count the number of distinct slopes among all pairs of points.
Input
- Line 1: A single integer .
- Lines 2..: Line contains two space-separated integers and , the coordinates of point .
Output
- A single integer: the maximum number of lines Bessie can draw, no two of which are parallel.
Hint
In the example, Bessie can draw lines of the four slopes -1, 0, 1/3, and 1.