Lining up Rabbit hunt POJ 1118 poj 2,606-point collinear problem.

Source: Internet
Author: User

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.

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.