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. Css 选择器总结

    选择器 .class 类对应的元素. #id 对应的id元素. * 全部元素 div{} 对应的标签 div,p{} 全部的div和p div p{} div下全部的p标签 div>p{} di ...

  2. 软件project总结

    软件project的文档完结了.在这里面学到了好多东西.也通过它分析了对机房收费系统进行了更加具体的分析.尽管早就明确了之间的联系,可是越温习越体会到逻辑的重要性和全心全意为人民服务的精神. 这些文档 ...

  3. 78.Nodejs基础中间件Connect

    转自:https://www.cnblogs.com/chris-oil/p/5625437.html 前言 “中间件”在软件领域是一个非常广的概念,除操作系统的软件都可以称为中间件,比如,消息中间件 ...

  4. HDU 5883 欧拉回路

    题面: 思路: 这里面有坑啊啊啊-.. 先普及一下姿势: 判断无向图欧拉路的方法: 图连通,只有两个顶点是奇数度,其余都是偶数度的. 判断无向图欧拉回路的方法: 图连通,所有顶点都是偶数度. 重点:图 ...

  5. MessageFormat

    MessageFormat mf = new MessageFormat("{0,number,#.##}, {0,number,#.#}"); Object[] objs = { ...

  6. win7安装两个jdk,1.7和1.8,下载、安装、配置环境变量,方便切换

    之前用过1.6,后来换电脑后用的1.7,由于时代在发展,许多插件.框架等新的功能需要jdk1.8才能使用,所以就想安装1.8,不过1.7还不准备卸载,就考虑安装多个jdk. 先下载jdk1.8,建议去 ...

  7. nodeType 节点的类型

    元素结点 1 属性结点 2 attributes 文本结点 3 注释结点   8 document结点 9 documentFragment 11 文档碎片

  8. 网络地图WebMap介绍

    WebMap是从ArcGIS Online或者ArcGIS for Portal item上获取显示到用户的界面中. 需要的是地图的ID. 创建一个新的网络地图需要设置ID号,然后再用地图底图MapV ...

  9. ADB高级应用

    ADB高级应用 一.利用无线来查看adb shell > adb tcpip 5555 连接: > adb connect IP:5555 见后文<调试注意事项> 二.模拟按键 ...

  10. linux c statfs系统调用

    statfs 系统调用原型: int statfs(const char *path, struct statfs *buf); 參数说明: path : 位于须要查询信息的文件系统的路径名(不是设备 ...