枚举,排序。

先将所有点按双关键字排序,然后枚举线的顶点$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. HttpClient 检索与获取过程数据

    使用 HttpClient 检索与获取过程数据   对于System.Net.Http的学习(一)——System.Net.Http 简介 对于System.Net.Http的学习(二)——使用 Ht ...

  2. 推荐系列:最小与最大[DP+余式定理]

    最小与最大 [问题描述] 做过了乘积最大这道题,相信这道题也难不倒你. 已知一个数串,可以在适当的位置加入乘号(设加了k个,当然也可不加,即分成k+1个部分),设这k+1个部分的乘积(如果k=0,则乘 ...

  3. vijos1009:扩展欧几里得算法

    1009:数论 扩展欧几里得算法 其实自己对扩展欧几里得算法一直很不熟悉...应该是因为之前不太理解的缘故吧这次再次思考,回看了某位大神的推导以及某位大神的模板应该算是有所领悟了 首先根据题意:L1= ...

  4. Leetcode::JumpGame

    Description: Given an array of non-negative integers, you are initially positioned at the first inde ...

  5. tomcat安装和基本配置

    首先,默认电脑上已经配置好java环境. 在http://tomcat.apache.org/这里下载tomcat二进制版本,下载到本地后随意解压在某个盘, 我解压在D:\apache-tomcat- ...

  6. vs2015开发Windows服务

    工作已经很久,时隔这么长时间写这篇文章是给自己以后做参考.也不至于以后长时间不写Windows服务而忘记整个开发过程.windows服务开发,基础的就不说了,直接上过程. 1.新建windows服务项 ...

  7. linux挂载分区

    [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda2 36G .3G 32G % / tmpf ...

  8. python文件的中文处理以及个人思路

    环境:ubuntu12.04 python2.7  涉及:ascii,utf-8,gbk,gb2312 首先说下个人处理过程中遇到的问题: 任务是这样:有大概4000个txt,将他们合并到一个文件里, ...

  9. asp.net mvc4设置area里面使用相同的 Controller 名称并设置area里的页面为起始页

    asp.net mvc4设置area里面使用相同的 Controller 名称并设置area里的页面为起始页 1.使用重名controller 在asp.net mvc2以后的版本里面,有了area( ...

  10. 做了一个quartz用到的cron在线生成器

    做了一个quartz用到的cron在线生成器 做了一个quartz用到的cron在线生成器   做这个的目的是前期在做Quartz时老是不知道如何去写,我想也有很多人和我一样吧. 有一次使用了一个老外 ...