POJ 2780 linearity most common line point classic problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.