UVALive5379 UVA270 lining up

Source: Internet
Author: User

Regionals 1994 >> North America-east Central NA

Problem Link: UVALive5379 UVA270 lining up.

Test Instructions Brief description: Enter n, enter n integer pairs, or n coordinate points, and ask what is the maximum number of collinear points.

Problem Analysis: The use of violence to solve this problem, fortunately, the size of the calculation is not big.

In the program, when judging collinear, using multiplication, no division, can guarantee accurate calculation results.

It is particularly necessary to note that although the problem is the same as POJ1118 HDU1432 lining up, the data input format is different and requires special handling. The program writes the function Mygetline () implementation to read a line, in place of the C language library function get () (The new C function library standard, the function gets () has been removed, because the function is prone to problems). In the function Mygetline () , you need to consider the case of EOF, which is a place that programmers can easily ignore.

In addition, the function sscanf () is also used in the program.

The C language Program of AC is as follows:

/* UVALive5379 UVA270 lining up */#include <stdio.h> #define MAXN 700struct {int x, y;} P[MAXN];    /* Point */void mygetline (char *pc) {char C;    while ((C=getchar ())! = ' \ n ' && c!=eof) *pc++ = c; *pc = ' + ';}    int main (void) {int T, n, ans, Max, I, J, K;    Char s[128];    scanf ("%d", &t);    GetChar ();    GetChar ();        while (t--) {n = 0;        Mygetline (s);            while (s[0]! = ' + ') {sscanf (S, "%d%d", &p[n].x, &AMP;P[N].Y);            n++;        Mygetline (s);        } ans = 2;                For (i=0, i<n; i++) for (j=i+1; j<n; J + +) {max = 2;                         for (k=j+1; k<n; k++) if ((p[j].x-p[i].x) * (p[k].y-p[j].y) = = (P[J].Y-P[I].Y) * (p[k].x-p[j].x))                max++;            if (max > ans) ans = max;        } printf ("%d\n", ans);    if (t) printf ("\ n"); } return 0;}


UVALive5379 UVA270 lining up

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.