POJ 1118 Lining Up 直线穿过最多的点数
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 直线穿过最多的点数的更多相关文章
- Leetcode 149.直线上最多的点数
直线上最多的点数 给定一个二维平面,平面上有 n 个点,求最多有多少个点在同一条直线上. 示例 1: 输入: [[1,1],[2,2],[3,3]] 输出: 3 解释: ^ | | o ...
- Java实现 LeetCode 149 直线上最多的点数
149. 直线上最多的点数 给定一个二维平面,平面上有 n 个点,求最多有多少个点在同一条直线上. 示例 1: 输入: [[1,1],[2,2],[3,3]] 输出: 3 解释: ^ | | o | ...
- UVa 270 & POJ 1118 - Lining Up
题目大意:给一些点,找出一条直线使尽可能多的点在这条直线上,求这条直线上点的个数. 以每一个点为原点进行枚举,求其它点的斜率,斜率相同则说明在一条直线上.对斜率排序,找出斜率连续相等的最大长度. #i ...
- poj 1118 Lining Up(水题)
再思考一下好的方法,水过,数据太弱! 本来不想传的! #include <iostream> using namespace std; #define MAX 702 /*284K 422 ...
- POJ 1118 Lining Up
枚举,排序. 先将所有点按双关键字排序,然后枚举线的顶点$P$,剩余的点以$P$为中心进行极角排序,可以取个$gcd$,这样一样的点就排在一起了,然后统计一下更新答案. #pragma comment ...
- [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. ...
- leetcode 149. 直线上最多的点数 解题报告
给定一个二维平面,平面上有 n 个点,求最多有多少个点在同一条直线上. 示例 1: 输入: [[1,1],[2,2],[3,3]] 输出: 3 解释: ^ | | o | o | o +------- ...
- 149 Max Points on a Line 直线上最多的点数
给定二维平面上有 n 个点,求最多有多少点在同一条直线上. 详见:https://leetcode.com/problems/max-points-on-a-line/description/ Jav ...
- Max Points on a Line(直线上最多的点数)
给定一个二维平面,平面上有 n 个点,求最多有多少个点在同一条直线上. 示例 1: 输入: [[1,1],[2,2],[3,3]] 输出: 3 解释: ^ | | o | o | ...
随机推荐
- rac_grid自检提示缺少pdksh-5.2包
原创作品,出自 "深蓝的blog" 博客,欢迎转载,转载时请务必注明下面出处,否则追究版权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlo ...
- BZOJ5105: [CodePlus2017]晨跑
[传送门:BZOJ5105] 简要题意: 给出a,b,c,求a,b,c的最小公倍数 题解: 直接搞(最近刷水题有点心态爆炸) 参考代码: #include<cstdio> #include ...
- 如何更改jar包源码
首先将你要更改的源码文件在eclipse中编译成.class文件 再找到你需要更改的.jar包 在桌面右键新建个文件夹把你要改的.jar包ctrl+c和ctrl+v 准备好一个压缩工具(这里推荐234 ...
- JAVA线程队列BlockingQueue
JAVA线程队列BlockingQueue 介绍 BlockingQueue阻塞队列,顾名思义,首先它是一个队列,通过一个共享的队列,可以使得数据由队列的一端输入,从另外一端输出. 常用的队列主要有以 ...
- sql中 where语句的用法
//查询user_id 10到20 之间 30到40之间 //查询user_id 不在10到20之间的
- Flex 集合 ArrayCollection 的使用
转:http://keren.iteye.com/blog/380847 转:http://callan.iteye.com/blog/335551 集合是ActionScript 中功能强大的基于索 ...
- Linux Mint 19.1将采用新的桌面布局
我们期待Linux Mint 19.1的发布在圣诞节假期之前到来,希望它会带来一些惊喜. Linux 19.1版本将默认包含Cinnamon 4.0桌面环境,Mint的开发人员说,这将比现在“看起来更 ...
- https soap链接示例
1.先安装soap扩展sudo yum install php-soap 2.安装openssL 3.function issure($sn){//通过soap链接接口 进行确认是否是正确的sn码 ...
- 几种类型的db,以及最新的db排名,看一下
5月数据库排名: http://geek.csdn.net/news/detail/196118 另外这篇文章里面提到了一些内嵌式数据库: http://blog.csdn.net/leagoal/a ...
- udacity android 学习笔记: lesson 4 part a
udacity android 学习笔记: lesson 4 part a 作者:干货店打杂的 /titer1 /Archimedes 出处:https://code.csdn.net/titer1 ...