枚举,排序。

先将所有点按双关键字排序,然后枚举线的顶点$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. AgileEAS.NET SOA中间件平台/敏捷软件开发平台

    AgileEAS.NET SOA中间件平台/敏捷软件开发平台 最新下载 一.前言 AgileEAS.NET SOA中间件平台,简称EAS.NET,是基于敏捷并行开发思想和Microsoft .Net构 ...

  2. IOS 跳转到系统的url

    About — prefs:root=General&path=AboutAccessibility — prefs:root=General&path=ACCESSIBILITYAi ...

  3. 【DOS】这个命令太牛逼了

    删除一个程序了后 竟然上不了网了 运行下列命令重启后就可以了 实在是救了我系统一命 命令如下: netsh winsock reset

  4. 竞价广告系统-ZooKeeper介绍

    ZooKeeper介绍 为了讲述的完整性,介绍一下ZooKeeper.ZooKeeper在Index和Ad Server里使用比较多,虽然它可能没有google的Chubby好,但它是开源的工具.举一 ...

  5. 使用entity framework开发oracle

    A.vs2010 SP1 B.ODAC(http://www.oracle.com/technetwork/database/windows/downloads/index-101290.html) ...

  6. MySql主从配置实践及其优势浅谈

    MySql主从配置实践及其优势浅谈 1.增加两个MySQL,我将C:\xampp\mysql下的MYSQL复制了一份,放到D:\Mysql2\Mysql5.1 修改my.ini(linux下应该是my ...

  7. Sqlserver 2008安装

    ##本文档所有安装操作都使用自动化脚本----###安装脚本的参数```#!setsaPassword=pass@word1 //sa数据库密码sqlComponent=SQLENGINE,REPLI ...

  8. JavaScript面向对象编程(二)构造函数和类

    new关键字和构造函数 在文章JavaScript面向对象编程(一)原型与继承中讨论啦JavaScript中原型的概念,并且提到了new关键字和构造函数.利用new关键字构造对象的实例代码如下: // ...

  9. 更有效率的使用Visual Studio2

    PS色调均化滤镜的快捷实现(C#源代码). photoshop色调均化功能通常是在进行修片处理前期比较常用的功能之一,其对扩展图像的对比度,增强视觉效果有一定的作用.在很多课本或者文章中,也称这种处理 ...

  10. <mate>标签中属性/值的各个意思

    <mate>标签中属性/值的各个意思 HTML 4 name 属性 1.<mate name="author" content="" /> ...