POJ 1018 & HDU 1432 lining up "simple geometry"

Source: Internet
Author: User

Lining up
Time Limit: 2000MS Memory Limit: 32768K
Total Submissions: 24786 Accepted: 7767

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!

Input

Input consist several Case,first line of the all case was an integer n (1 < n <), then follow n pairs of Intege Rs. Each pair of integers are separated by one blank and ended by a new-line character. The input ended by n=0.

Output

Output one integer for each input case, representing the largest number of points and all lie on one line.

Sample Input

51 12 23 39 1010 110

Sample Output

3

Source

East Central North America 1994
Original title Link: http://poj.org/problem?id=1118
Enter n points and ask how many points you have on the collinear, direct violence. Three-layer loop. Note: Hangzhou Electric test data is a bit large, cin timeout, but POJ can be too. AC Code:
#include <iostream> #include <cstdio>using namespace std;struct point{    int x, y;} A[705];int Main () {    int n;    Freopen ("Data/1018.txt", "R", stdin);    while (Cin>>n,n)    {        for (int i=0;i<n;i++)            scanf ("%d%d", &a[i].x,&a[i].y);            cin>>a[i].x>>a[i].y;        int maxx=2;        for (int i=0;i<n;i++)        {for            (int j=i+1;j<n;j++)            {                int ans=2;                for (int k=j+1;k<n;k++)                {                    if (a[j].x-a[i].x) * (a[k].y-a[j].y) = = (A[J].Y-A[I].Y) * (a[k].x-a[j].x))                        ans++;                    if (Ans>maxx)                        Maxx=ans;        }}} cout<<maxx<<endl;    }    return 0;}


POJ 1018 & HDU 1432 lining up "simple geometry"

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.