This topic I was violent made out, the complexity is n^3, because the array is more than 700 groups, about can use this complexity, although strictly speaking more than 500
is normal, each time is to select two coordinates and then determine a line, and then traverse the other points, with the cross-product form to decide whether in a straight line is OK
, the internet said can be used to solve the order of the polar angle, the complexity is n^2logn but I looked at and did not want to learn the desire ... Learn it later,,, and use it.
The SSCANF function, to see what others are using, is to match the desired type in an array ... This problem is the input of the pit. Between each of the two outputs
There is a blank line, and the last group cannot be followed by a blank line ... and the coordinate input has a blank line before ...
Post code:
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h>using namespace Std;struct node{int I,j;} A[705];int cmp (const void *a,const void *b) {if ((node *) a)->i! = ((node *) b)->i) return ((node *) a)->i-((node *) b)->i;return (node *) a)->j-((node *) b)->j;} int main () {int t,i,j,k;cin >> T;getchar (); GetChar (); while (t--) {int i = 1;char b[100];int n = 1;while (gets (b)!=null) {if (b[0] = = ' + ') break; SSCANF (b, "%d%d", &A[N].I,&A[N].J); n++;} n = N-1;qsort (a+1,n,sizeof (a[0]), CMP), int max = 2;for (i=1; i<=n; i++) {for (j=i+1; j<=n; J + +) {int sum = 2;for (k=j+1; k <=n; k++) {if ((A[J].J-A[I].J) * (a[k].i-a[j].i) = = (A[K].J-A[J].J) * (a[j].i-a[i].i)) {sum++;}} if (Sum > max) max = sum;}} cout << Max << endl;if (T! = 0) cout << Endl;} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UVA lining up (violence)