Given N points in 2-dimensional space, we need to print the count of the minimum number of lines which traverse through all these N points and which go through a specific (xO, yO) point also.
If given points are (-1, 3), (4, 3), (2, 1), (-1, -2), (3, -3) and (xO, yO) point is (1, 0) i.e. every line must go through this point. Then we have to draw at least two lines to cover all these points going through (xO, yO) as shown in below diagram.
We can solve this problem by considering the slope of all points with (xO, yO). If two distinct points have the same slope with (xO, yO) then they can be covered with same line only so we can track slope of each point and whenever we get a new slope we will increase our line count by one.
In below code slope is stored as a pair of integer to get rid of the precision problem and a set is used to keep track of occurred slopes.
Please see below code for better understanding.
This article is contributed by Utkarsh Trivedi. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find whether only two parallel lines contain all coordinates points or not
- Minimum distance to travel to cover all intervals
- Minimum number of points to be removed to get remaining points on one side of axis
- Non-crossing lines to connect points in a circle
- Count of different straight lines with total n points with m collinear
- Maximum points of intersection n lines
- Maximum points of intersections possible among X circles and Y straight lines
- Number of pairs of lines having integer intersection points
- Number of lines from given N points not parallel to X or Y axis
- Find the point on X-axis from given N points having least Sum of Distances from all other points
- Minimum squares to cover a rectangle
- Number of Integral Points between Two Points
- Count of obtuse angles in a circle with 'k' equidistant points between 2 given points
- Ways to choose three points with distance between the most distant points <= L
- Minimum Sum of Euclidean Distances to all given Points
- Number of squares of side length required to cover an N*M rectangle
- Maximum number of tiles required to cover the floor of given size using 2x1 size tiles
- Minimum area of a Polygon with three points given
- Pizza cut problem (Or Circle Division by Lines)
- Number of Triangles that can be formed given a set of lines in Euclidean Plane
Improved By : mohit kumar 29