Idea: First of all the points in accordance with the coordinates, and then at each point as the datum point, calculate the slope of the other points and the point line, the slope of all sorts after the same number of the same slope.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <string>7#include <vector>8#include <Set>9#include <map>Ten#include <queue> One#include <stack> A using namespacestd; -typedefLong LongLL; - ConstLL INF =0x4fffffff; the Const Doubleexp= 1e-6; - ConstLL MOD = 1e9+7; - Const intms= 1e5 +5 ; - + - struct Point + { A intx; at inty; - }points[ms]; - - DoubleK[ms]; - - intcmpConstPoint &a,ConstPoint &b) in { - if(A.x! =b.x) to returnA.x <b.x; + returnA.y <b.y; - } the * DoubleSlope (Point a,point B) $ {Panax Notoginseng if(a.x = =b.x) - returnINF; the Doublepx = a.x-b.x; + DoublePY = a.y-b.y; A returnPY/px; the } + - intMain () $ { $ intN; - intI,J,CNT,T,MAXV; - while(SCANF ("%d", &n)! = EOF &&N) the { - for(i =0; I < n;i++)Wuyiscanf"%d%d",&points[i].x,&points[i].y); theSort (points,points+n,cmp); -MAXV =-1; Wu for(i=0; I < n;i++) - { Aboutt=0; $ for(j = i+1; J < n;j++) - { -k[t++] =slope (points[i],points[j]); - } ASort (k,k+t); + for(j =1, cnt =1; J < t;j++) the { - if(Fabs (k[j]-k[j-1]) <EXP) $cnt++; the Else theCnt=1; the if(CNT >MAXV) theMAXV =CNT; - } in } theprintf"%d\n", maxv+1); the } About return 0; the}
Lining up Rabbit hunt POJ 1118 poj 2,606-point collinear problem.