枚举,排序。

先将所有点按双关键字排序,然后枚举线的顶点$P$,剩余的点以$P$为中心进行极角排序,可以取个$gcd$,这样一样的点就排在一起了,然后统计一下更新答案。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} const int maxn=;
int n,ans;
struct X{LL x,y;}s[maxn],t[maxn]; LL gcd(LL a,LL b)
{
if(b==) return a;
return gcd(b,a%b);
} bool cmp(X a,X b)
{
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
} LL ABS(LL a)
{
if(a<) a=-a;
return a;
} int main()
{
while(~scanf("%d",&n))
{
if(n==) break; ans=;
for(int i=;i<=n;i++) scanf("%lld%lld",&s[i].x,&s[i].y);
sort(s+,s++n,cmp);
for(int i=;i<=n;i++)
{
int sz=;
for(int j=i+;j<=n;j++)
{
t[sz].x=s[j].x-s[i].x;
t[sz].y=s[j].y-s[i].y;
LL GCD=gcd(ABS(t[sz].x),ABS(t[sz].y));
t[sz].x=t[sz].x/GCD;
t[sz].y=t[sz].y/GCD;
sz++;
} if(sz==) continue;
sort(t,t+sz,cmp); int k=;
for(int i=;i<sz;i++)
{
if(t[i].x==t[i-].x&&t[i].y==t[i-].y) k++;
else ans=max(ans,k+),k=;
}
ans=max(ans,k+);
}
printf("%d\n",ans);
}
return ;
}

POJ 1118 Lining Up的更多相关文章

  1. POJ 1118 Lining Up 直线穿过最多的点数

    http://poj.org/problem?id=1118 直接枚举O(n^3) 1500ms能过...数据太水了...这个代码就不贴了... 斜率排序O(n^2logn)是更好的做法...枚举斜率 ...

  2. poj 1118 Lining Up(水题)

    再思考一下好的方法,水过,数据太弱! 本来不想传的! #include <iostream> using namespace std; #define MAX 702 /*284K 422 ...

  3. UVa 270 & POJ 1118 - Lining Up

    题目大意:给一些点,找出一条直线使尽可能多的点在这条直线上,求这条直线上点的个数. 以每一个点为原点进行枚举,求其它点的斜率,斜率相同则说明在一条直线上.对斜率排序,找出斜率连续相等的最大长度. #i ...

  4. HDU 1432 Lining Up (POJ 1118)

    枚举,枚举点 复杂度为n^3. 还能够枚举边的,n*n*log(n). POJ 1118 要推断0退出. #include<cstdio> #include<cstring> ...

  5. 【同一直线最多点】 poj 1118+2606+2780

    poj 1118 #include<iostream> using namespace std; #define N 700 struct point {int x,y;} pnt[N]; ...

  6. 1118 Lining Up

    题目链接: http://poj.org/problem?id=1118 题意: 给定n个点, 求在同一直线上的点最多的直线上点的数目. 解法: 简单题目, 规模比较小,  暴力搜索. #includ ...

  7. POJ 1118

    #include<iostream> #include<set> #include<stdio.h> #include<math.h> #include ...

  8. POJ 1118 求平面上最多x点共线

    题意:给你n个点的坐标.求一条直线最多能穿过多少个点. 思路:枚举(n^2)+求斜率+排序 (复杂度n^2logn)大功告成 //By: Sirius_Ren #include <cmath&g ...

  9. 算法之路 level 01 problem set

    2992.357000 1000 A+B Problem1214.840000 1002 487-32791070.603000 1004 Financial Management880.192000 ...

随机推荐

  1. win32多线程-异步过程调用(asynchronous Procedure Calls, APCs)

    使用overlapped I/O并搭配event对象-----win32多线程-异步(asynchronous) I/O事例,会产生两个基础性问题. 第一个问题是,使用WaitForMultipleO ...

  2. [转]Data Structure Recovery using PIN and PyGraphviz

    Source:http://v0ids3curity.blogspot.com/2015/04/data-structure-recovery-using-pin-and.html --------- ...

  3. 使用 Aspose.Cells 实现 excel导入

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  4. 目标HttpController在ASP.NET Web API中是如何被激活的:目标HttpController的创建

    目标HttpController在ASP.NET Web API中是如何被激活的:目标HttpController的创建 通过上面的介绍我们知道利用HttpControllerSelector可以根据 ...

  5. ASP.NET MVC学习笔记-----Filter

    ASP.NET MVC学习笔记-----Filter(1) Filter类型 接口 MVC的默认实现 Description Authorization IAuthorizationFilter Au ...

  6. HtmlParser应用

    HtmlParser应用,使用Filter从爬取到的网页中获取需要的内容 { String url = "http://wenku.baidu.com/search?word=htmlpar ...

  7. NDepend 3.0已与Visual Studio集成

    NDepend 3.0已与Visual Studio集成 投递人 itwriter 发布于 2010-02-10 16:17 评论(0) 有1638人阅读  原文链接  [收藏]  « » NDepe ...

  8. kivy Grid Layout

    http://kivy.org/docs/api-kivy.uix.gridlayout.html?highlight=gridlayout#kivy.uix.gridlayout It's so n ...

  9. AJAX实现无刷新验证用户名

    register.php <html> <head> <meta http-equiv="content-type" content="te ...

  10. jquery代码实现简单的五星评价功能!

    实现: 1,鼠标移动到第三个星星,则一二三星星变亮,后两个变暗 2,鼠标点击某个星星后,可以继续选择,但拿开后星星会定格住你点击的位置 <script type="text/javas ...