http://poj.org/problem?id=1118

直接枚举O(n^3) 1500ms能过...数据太水了...这个代码就不贴了...

斜率排序O(n^2logn)是更好的做法...枚举斜率...直线方程相同的线段数量k...一定满足方程 n(n-1)/2=k  ---------------  还真是baka. 到2点才想出这个结论

特判只有一个点,两个点的情况...500ms AC

/********************* Template ************************/
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std; #define EPS 1e-8
#define MAXN (int)5e5+5
#define MOD (int)1e9+7
#define PI acos(-1.0)
#define LINF ((1LL)<<50)
#define INF (1<<30)
#define DINF (1e10)
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max3(a,b,c) (max(max(a,b),c))
#define min3(a,b,c) (min(min(a,b),c))
#define BUG cout<<"BUG! "<<endl
#define LLL cout<<"--------------"<<endl
#define L(t) (t << 1)
#define R(t) (t << 1 | 1)
#define Mid(a,b) ((a + b) >> 1)
#define lowbit(a) (a & -a)
#define FIN freopen("in.txt","r",stdin)
#define FOUT freopen("out.txt","w",stdout)
#pragma comment (linker,"/STACK:102400000,102400000") // typedef long long LL;
// typedef unsigned long long ULL;
// typedef __int64 LL;
// typedef unisigned __int64 ULL;
// int gcd(int a,int b){ return b?gcd(b,a%b):a; }
// int lcm(int a,int b){ return a*b/gcd(a,b); } /********************* F ************************/
struct POINT{
double x,y;
POINT(double _x = , double _y = ):x(_x),y(_y){};
int id;
}p[];
struct LINE{
POINT a,b;
double K,B;
LINE(POINT _a = ,POINT _b = ):a(_a),b(_b){
if((a.x - b.x) == ){
K = DINF;
B = a.x;
}else{
K = ((a.y - b.y) / (a.x - b.x));
B = (- (b.x * a.y - a.x * b.y) / (a.x - b.x));
}
}
}L[];
bool cmp(LINE a,LINE b){
if(a.K == b.K) return a.B < b.B;
return a.K < b.K;
}
int main()
{
//FIN;
int n;
while(cin>>n && n){
for(int i = ; i < n ; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
if(n == || n == ){
printf("%d\n",n);
continue;
}
int cnt = ;
for(int i = ; i < n ; i++)
for(int j = i+ ; j < n ; j++)
L[cnt++] = LINE(p[i],p[j]);
sort(L,L+cnt,cmp);
int m = -INF;
for(int i = ; i < cnt- ; i++){
int c = ;
while(L[i].K == L[i+].K && L[i].B == L[i+].B){
c++;
i++;
}
c = sqrt((c+)*)+;
m = max(m,c);
}
printf("%d\n",m);
}
return ;
}

POJ 1118 Lining Up 直线穿过最多的点数的更多相关文章

  1. Leetcode 149.直线上最多的点数

    直线上最多的点数 给定一个二维平面,平面上有 n 个点,求最多有多少个点在同一条直线上. 示例 1: 输入: [[1,1],[2,2],[3,3]] 输出: 3 解释: ^ | |        o ...

  2. Java实现 LeetCode 149 直线上最多的点数

    149. 直线上最多的点数 给定一个二维平面,平面上有 n 个点,求最多有多少个点在同一条直线上. 示例 1: 输入: [[1,1],[2,2],[3,3]] 输出: 3 解释: ^ | | o | ...

  3. UVa 270 & POJ 1118 - Lining Up

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

  4. poj 1118 Lining Up(水题)

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

  5. POJ 1118 Lining Up

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

  6. [Swift]LeetCode149. 直线上最多的点数 | Max Points on a Line

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

  7. leetcode 149. 直线上最多的点数 解题报告

    给定一个二维平面,平面上有 n 个点,求最多有多少个点在同一条直线上. 示例 1: 输入: [[1,1],[2,2],[3,3]] 输出: 3 解释: ^ | | o | o | o +------- ...

  8. 149 Max Points on a Line 直线上最多的点数

    给定二维平面上有 n 个点,求最多有多少点在同一条直线上. 详见:https://leetcode.com/problems/max-points-on-a-line/description/ Jav ...

  9. Max Points on a Line(直线上最多的点数)

    给定一个二维平面,平面上有 n 个点,求最多有多少个点在同一条直线上. 示例 1: 输入: [[1,1],[2,2],[3,3]] 输出: 3 解释: ^ | |        o |     o | ...

随机推荐

  1. HDU 3008 Warcraft

    题意:一个人有100点血和100点魔法,Boss有100点血.人有n个技能.每一个技能对Boss有a[i]点伤害, 且会消耗b[i] 的点魔量,人每秒会有t秒魔法恢复(最大为100)Boss每秒有q点 ...

  2. Win8.1应用开发之文件操作

    在操作文件之前,先相应用的应用功能声明进行设定.用户通过C#(非UI)对win8.1上的文件进行訪问,仅仅能局限于图片,音乐,视频和文档四个目录. 而通过文件选取器则能訪问到整个系统的文件. (一)应 ...

  3. 15.Intellij中配置jdk/tomcat/maven

    转自:https://blog.csdn.net/u010414666/article/details/44465905 继上一篇安装好了Intellij之后,我们可以对Intellij,做一些简单的 ...

  4. JWT Authentication Tutorial: An example using Spring Boot--转

    原文地址:http://www.svlada.com/jwt-token-authentication-with-spring-boot/ Table of contents: Introductio ...

  5. MFC- OnIdle空闲处理

    CWinApp::OnIdlevirtual BOOL OnIdle( LONG lCount );返回值: 如果要接收更多的空闲处理时间,则返回非零值:如果不需要更多的空闲时间则返回0.参数: lC ...

  6. Linux系统消息队列框架Kafka单机安装配置

    http://www.ithao123.cn/content-11128587.html

  7. 修正单纯形法&#183;优化算法实现&#183;Java

    修正单纯性法 代码例如以下: 舍去了输入转化的内容,主要包括算法关键步骤. public class LPSimplexM { private static final double inf = 1e ...

  8. HDOJ 5414 CRB and String 模拟

    CRB and String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) T ...

  9. vim 实际行跟屏幕行移动命令

    我们使用vim的时候,经常会碰到那种情况,就是我们输入的内容过长,中间一直不换行.当我们一行的长度超出电脑屏幕的时候,我们会发现这时候文字自动换行了.不过,如果你使用行号看的话,其实这新的一行是没有行 ...

  10. Typedef和#define之间的区别

    Typedef和define都可以用来给对象取一个别名,但是两者却有着很大不同. 1. 首先,二者执行时间不同 关键字typedef在编译阶段有效,由于是在编译阶段,因此typedef有类型检查的功能 ...