Hdoj 1432 lining up "cross product"

Source: Internet
Author: User

Lining upTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 1094 Accepted Submission (s): 307


Problem Description "How am I ever going to solve this problem?" said the pilot.


Indeed, the pilot is not facing a easy task. She had to drop packages at specific points scattered in a dangerous area. Furthermore, the pilot could only fly through the area once in a straight line, and she had to fly over as many points as Pos Sible. All points were given by means of the integer coordinates in a two-dimensional space. The pilot wanted to know the largest number of points from the given set, all lie on one line. Can you write a program that calculates this number?

Your program have to be efficient!

Inputthe input consists of multiple test cases, and each case begins with a single positive integer on a line by itself in Dicating the number of points, followed by N pairs of integers, where 1 < N < 700. Each pair of integers are separated by one blank and ended by a new-line character. No pair would occur twice in one test case.


Outputfor Each test case, the output consists of one integer representing the largest number of the points so all lie on one Line, one line per case.
Sample Input
51 12 23 39 1010 11

Sample Output
3

Test instructions: Give some coordinates and ask how many points are in the same line

Strategy: collinear vector cross product is 0, cross product formula such as a (x1, y1), b(x2, y2) a*b = x1*y2-x2*y1

Code:

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>const int M = 750; Using namespace std;struct node{    int x, y;} S[m];bool f (Node A, node B, node C) {    return ((a.x-c.x) * (B.Y-C.Y)-(A.Y-C.Y) * (b.x-c.x) = = 0);//}int Main () {    int n;< C3/>while (scanf ("%d", &n) = = 1) {for        (int i = 0; i < n; + + i) {            scanf ("%d%d", &s[i].x, &s[i].y);        }        int ans = 0, cou = 0;        for (int i = 0; i < n; + + i) {for            (int j = i+1; J < N; + + j) {                cou = 0;                for (int k = j+1; k < n; + + k) {                    if (f (s[i], s[j], s[k])) ++cou;                }                ans = max (ans, cou);            }        }        printf ("%d\n", ans+2);    }    return 0;}

Hdoj 1432 lining up "cross product"

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.