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, &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