题意:给你n个点的坐标。求一条直线最多能穿过多少个点。

思路:枚举(n^2)+求斜率+排序 (复杂度n^2logn)大功告成

//By: Sirius_Ren
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,maxx;double s[705];
struct line{int x,y;}a[705];
bool cmp(line a,line b){return a.x<b.x;}
int main()
{
while(scanf("%d",&n)&&n){
maxx=0;
for(int i=1;i<=n;i++)
scanf("%d%d",&a[i].x,&a[i].y);
sort(a+1,a+1+n,cmp);
for(int i=1;i<n;i++){
int tot=1,ans=0;
for(int j=i+1;j<=n;j++)
s[tot++]=(1.0*a[j].y-1.0*a[i].y)/(1.0*a[j].x-1.0*a[i].x);
sort(s+1,s+tot);
for(int i=1;i<tot-1;i++)
if(fabs(s[i+1]-s[i])<1e-6)ans++,maxx=max(maxx,ans);
else ans=0;
}
printf("%d\n",maxx+2);
}
}

POJ 1118 求平面上最多x点共线的更多相关文章

  1. TZOJ 1689 Building A New Barn(求平面上有几个其它点求到n个点的曼哈顿距离最小)

    描述 After scrimping and saving for years, Farmer John has decided to build a new barn. He wants the b ...

  2. POJ 2187 求凸包上最长距离

    简单的旋转卡壳题目 以每一条边作为基础,找到那个最远的对踵点,计算所有对踵点的点对距离 这里求的是距离的平方,所有过程都是int即可 #include <iostream> #includ ...

  3. POJ C程序设计进阶 编程题#4:寻找平面上的极大点

    编程题#4:寻找平面上的极大点 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描 ...

  4. poj 1106(半圆围绕圆心旋转能够覆盖平面内最多的点)

    Transmitters Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4955   Accepted: 2624 Desc ...

  5. [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. ...

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

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

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

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

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

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

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

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

随机推荐

  1. HDU 1465(错排公式)

    不容易系列之一 题意: 一个人要寄n个信封,结果装错了.信纸的编号为1到n,信封的编号为1到n,信纸的编号不能和信封的编号一样,全都不能一样. 思路:错排公式. D(n)表示n件信封装错的所有的情况. ...

  2. 获取springbean的几种方式

    首先我说一下我遇到的问题,再项目初始化时候,spring容器初始化前要执行的操作中使用到了bean去做一些增删改查操作,这样做是不能自己使用springbean的数据源去操作的,所以需要动态获取spr ...

  3. Ajax基本写法

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. Problem 21

    Problem 21 https://projecteuler.net/problem=21 Let d(n) be defined as the sum of proper divisors of  ...

  5. LINUX应用开发(面试)

    LINUX应用开发工程师职位 本试卷从考试酷examcoo网站导出,文件格式为mht,请用WORD/WPS打开,并另存为doc/docx格式后再使用 说明:应用开发可考察的点非常多,关键的还是C语言和 ...

  6. PAT 1039. Course List for Student

    Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists o ...

  7. 5.2.2 re模块方法与正则表达式对象

    Python标准库re提供了正则表达式操作所需要的功能,既可以直接使用re模块中的方法,来实现,也可以把模式编译成正则表达式对象再使用. 方法 功能说明 complie(pattern[,flagss ...

  8. ssm 数据库连接池配置

    1.工程引入druid-1.1.2.jar包2.修改spring-common.xml文件 <!-- 1. 数据源 : DruidDataSource--> <bean id=&qu ...

  9. 2017 Multi-University Training Contest - Team 4 Classic Quotation

    Classic Quotation Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Othe ...

  10. RestEasy 用户指南---第11章 @FormParam

    转载说明出处:http://blog.csdn.net/nndtdx/article/details/6870391 原文地址 http://docs.jboss.org/resteasy/docs/ ...