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

/**
* Definition for a point.
* struct Point {
* int x;
* int y;
* Point() : x(0), y(0) {}
* Point(int a, int b) : x(a), y(b) {}
* };
*/
class Solution {
public:
int maxPoints(vector<Point> &points) {
if(points.size()<)return points.size();
int sizeMax=;
for(int i=;i<points.size();i++)
{
int repeat=;
map<double,int> smap;
smap.clear();
for(int j=;j<points.size();j++)
{
if(i==j)continue;
if(points[i].x==points[j].x&&points[i].y==points[j].y)
{
repeat++;
continue;
}
double k=points[i].x==points[j].x?INT_MAX:double(points[j].y-points[i].y)/(points[j].x-points[i].x);
smap[k]++;
}
if(smap.size()==)
{
sizeMax=sizeMax>repeat?sizeMax:repeat;
continue;
}
for(map<double,int>::iterator iter=smap.begin();iter!=smap.end();iter++)
{
sizeMax=sizeMax>(iter->second+repeat)?sizeMax:(iter->second+repeat);
}
}
return sizeMax;
}
};

leetcode[149]Max Points on a Line的更多相关文章

  1. [leetcode]149. 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. ...

  2. [LeetCode] 149. 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. ...

  3. Java for LeetCode 149 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. ...

  4. leetcode 149. Max Points on a Line --------- java

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

  5. 【LeetCode】149. Max Points on a Line

    Max Points on a Line Given n points on a 2D plane, find the maximum number of points that lie on the ...

  6. 【leetcode】Max Points on a Line

    Max Points on a Line 题目描述: Given n points on a 2D plane, find the maximum number of points that lie ...

  7. [LeetCode OJ] Max Points on a Line

    Max Points on a Line Submission Details 27 / 27 test cases passed. Status: Accepted Runtime: 472 ms ...

  8. 【LeetCode】149. Max Points on a Line 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典+最大公约数 日期 题目地址:https://l ...

  9. 149. Max Points on a Line

    题目: Given n points on a 2D plane, find the maximum number of points that lie on the same straight li ...

随机推荐

  1. vim Podfile

    platform :ios, "7.0"pod "AFNetworking"pod "SDWebImage"pod "SVProg ...

  2. Scroll View 深入

    转载自:http://mobile.51cto.com/hot-430409.htm 可能你很难相信,UIScrollView和一个标准的UIView差异并不大,scroll view确实会多一些方法 ...

  3. 基于js脚本的单机黄金点游戏

    题目描述 N个同学(N通常大于10),每人写一个0-100之间的有理数 (不包括0或100),交给裁判,裁判算出所有数字的平均值,然后乘以0.618(所谓黄金分割常数),得到G值.提交的数字最靠近G( ...

  4. android usb挂载分析---MountService启动

    android usb挂载分析---MountService启动 分类: android框架 u盘挂载2012-03-27 23:00 11799人阅读 评论(4) 收藏 举报 androidsock ...

  5. Codeforces#373 Div2

    Ranting重新回到浅蓝的一场比赛 Problem A 题意:月亮的大小是按照这样的顺序排列的0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ...

  6. vs2008安装opencv2.4.6

    最近安装opencv2.4.6,发现犯了一个很愚蠢的错误,在此记录一下. opencv的头文件包含应该位于build文件夹内,而我误将opencv文件夹下的include包含了进去,造成无法找到头文件 ...

  7. ibatis一对多 数据库设计及实现

    iBatis的多表关联. ibatis的表关联,和数据库语句无关,是在Java程序中,把若干语句的结果关联到一起.这种关联形式,虽然在大数据量时是很奢侈的行为,但是看起来很干净,用起来也很方便. 这里 ...

  8. Struts2 JSP中将list,set ,Map传递到Action然后遍历(三十五) - 雲淡風輕 - ITeye技术网站

    1.使用Strut2的的集合对象:在jsp初始化action中的list然后提交到action2.使用Struts标签,实现多个用户同时注册(注意属性配置文件)3.pojo package com.s ...

  9. 【转贴】 Flex 预编译处理 与 手机项目、Web项目、Air项目自由转换

    原文连接: http://bbs.9ria.com/forum.php?mod=viewthread&tid=263350#lastpost 由于这个论坛不稳定,所以转到这里来,这个帖子蛮有用 ...

  10. ComboBox值排序

    ComboBox值排序先是想通过冒泡排序,但是冒泡排序是int类型,又打算通过下标,进行字符串排序,然后想到了一个简单的办法……先存入ArrayList排序Sort清空ComboBox再遍历存入 ...