POJ 1118 Lining Up
枚举,排序。
先将所有点按双关键字排序,然后枚举线的顶点$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的更多相关文章
- POJ 1118 Lining Up 直线穿过最多的点数
http://poj.org/problem?id=1118 直接枚举O(n^3) 1500ms能过...数据太水了...这个代码就不贴了... 斜率排序O(n^2logn)是更好的做法...枚举斜率 ...
- poj 1118 Lining Up(水题)
再思考一下好的方法,水过,数据太弱! 本来不想传的! #include <iostream> using namespace std; #define MAX 702 /*284K 422 ...
- UVa 270 & POJ 1118 - Lining Up
题目大意:给一些点,找出一条直线使尽可能多的点在这条直线上,求这条直线上点的个数. 以每一个点为原点进行枚举,求其它点的斜率,斜率相同则说明在一条直线上.对斜率排序,找出斜率连续相等的最大长度. #i ...
- HDU 1432 Lining Up (POJ 1118)
枚举,枚举点 复杂度为n^3. 还能够枚举边的,n*n*log(n). POJ 1118 要推断0退出. #include<cstdio> #include<cstring> ...
- 【同一直线最多点】 poj 1118+2606+2780
poj 1118 #include<iostream> using namespace std; #define N 700 struct point {int x,y;} pnt[N]; ...
- 1118 Lining Up
题目链接: http://poj.org/problem?id=1118 题意: 给定n个点, 求在同一直线上的点最多的直线上点的数目. 解法: 简单题目, 规模比较小, 暴力搜索. #includ ...
- POJ 1118
#include<iostream> #include<set> #include<stdio.h> #include<math.h> #include ...
- POJ 1118 求平面上最多x点共线
题意:给你n个点的坐标.求一条直线最多能穿过多少个点. 思路:枚举(n^2)+求斜率+排序 (复杂度n^2logn)大功告成 //By: Sirius_Ren #include <cmath&g ...
- 算法之路 level 01 problem set
2992.357000 1000 A+B Problem1214.840000 1002 487-32791070.603000 1004 Financial Management880.192000 ...
随机推荐
- 【javascript】判断浏览设备是手机还是电脑
判断页面浏览设备是手机还是电脑,代码如下: function browserRedirect() { var sUserAgent = navigator.userAgent.toLowerCase( ...
- 聊天工具mychat
python学习,自己写了个简单聊天工具mychat 最近在学习python,自己写了个最最简单的聊天工具mychatv0.1. 第一版,完成基本的聊天功能. GUI用的是自带的TKinter,用到的 ...
- 读取xml并将节点保存到Excal
using NPOI.HPSF; using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using System; using System.Coll ...
- Make Things Move -- Javascript html5版(一)文件目录结构和工具方法准备
从这一篇开始,就来开始我们的make things move之旅吧 在此之前,要知道ActionScript(AS)的语法和JS是不一样的,AS是相对于JS而言更好的支持了面向对象的特性,所以我们可以 ...
- ASP.NET MVC3开发 - CodeFisrt数据库篇之M层验证之调用远程方法(Remote)验证
本文讲述在作者在使用.net mvc3进行开发的时候用到的两种调用远程验证的方法,第一种方法比较傻瓜,第二种方法方便好用,调用远程验证是个比较常见的验证方法,比如注册用户时的用户名唯一性验证. 作者原 ...
- 物理数据模型(PDM)->概念数据模型 (CDM)->面向对象模型 (OOM):适用于已经设计好数据库表结构了。
物理数据模型(PDM)->概念数据模型 (CDM)->面向对象模型 (OOM):适用于已经设计好数据库表结构了. 步骤如下: 一.反向生成物理数据模型PDM 开发环境 PowerDes ...
- DNS:域名系统
DNS:域名系统 1.DNS DNS 是计算机域名系统(Domain Name System 或Domain Name Service) 的缩写,它是由解析器以及域名服务器组成的.域名服务器 ...
- 数模学习笔记(五)——BP神经网络
1.BP神经网络是一种前馈型网络(各神经元接受前一层的输入,并输出给下一层,没有反馈),分为input层,hide层,output层 2.BP神经网络的步骤: 1)创建一个神经网络:newff a.训 ...
- flask tutorial => make a blog :) flask 搭建博客系统从零开始!
please follow the tutorial from the official site :) http://flask.pocoo.org/docs/ You could download ...
- 搭建WEB邮件系统,爆强!
Linux+postfix+extmail+dovecot打造基于web页面的邮件系统 原文地址: http://blog.csdn.net/deansrk/article/details/67177 ...