Test instructions
Give n points, with a maximum number of points collinear (n<1000).
Analysis:
This is a classic problem, naïve n^3 solution: Enumerate n^2 lines, judging how many points each line intersects, complexity n^3. Will obviously time out. This is the solution of N^2logn: Enumerate each point, the n lines of a point and other points are sorted by slope, and set the line with the same slope in those lines with k bars, then K updates the answer. Here want to focus on the slope of the problem, many online code is directly calculate the slope, but the calculation of the geometry of the topic is not recommended slope, preferably with a fork product to replace all the calculation of the slope, because 1) slope of the value range is very large, if there is a middle calculation is easy to explode data expression range, for the accuracy of the problem 2) If you define inf=100000000 to represent the slope of infinity, then what if the slope of a straight line in the title is Inf+1? 3) Calculate the slope involves division, everywhere to special enigmatic grading mother, cause the program is not concise also prone to error 4) cross product and dot product is a more profound description of the point line relationship than the slope, can represent the relationship between the point line, the inverse relationship, etc. Sometimes the point line translation can also be in the cross product point product operation to form a partial sequence set (the problem code in the inverse of the line is to form a partial sequence set), and the partial sequence set can be more than a lot of means to deal with. Therefore, it is suggested that the slope should be considered less in the calculation geometry, starting from the point product cross product.
Code:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ 2780 linearity up to a common line point classic problem