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. ural1682 Crazy Professor

    Crazy Professor Time limit: 1.0 secondMemory limit: 64 MB Professor Nathan Mathan is crazy about mat ...

  2. hide the navigationBar and tabBar

    [self.navigationController setNavigationBarHidden:YES animated:NO]; hidesBottomBarWhenPushed

  3. jQuery+CSS实现的图片滚动效果

    http://www.helloweba.com/view-blog-139.html

  4. codeforces 665C Simple Strings

    相同的一段字母变一下就可以. #include<cstdio> #include<cstring> #include<cmath> #include<vect ...

  5. C++多线程一

    CreateThread()创建一个新的线程. ExitThread()正常的结束一个线程的执行. CloseHandle()关闭一个线程的句柄. CreateThread()函数原型如下: HAND ...

  6. Base64编码Java实现

    一.什么是Base64编码 Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一.Base64 主要不是加密,它主要的用途是把一些二进制数转成普通字符用于网络传输. 由于一些二进制字符在 ...

  7. thin-provisioning-tools

    公司我还用着squeeze,没这个包,下载编译:https://github.com/jthornber/thin-provisioning-tools.git

  8. mytop

    http://jeremy.zawodny.com/mysql/mytop/mytop.html 内容有点过时,用?查看帮助 vi set nuset nonu总记不住

  9. 将一个字典内的内value转换为集合:返回一个数组,此数组中包含输入字典的键值对中的数组的所有元素(为NSArray添加category)

    - (NSArray *)testa:(NSDictionary *)dic { NSMutableArray *arr_M = [NSMutableArray array]; // 1.遍历每一个元 ...

  10. mousewheel,DOMMouseScroll判断滚轮滚动方向

    firefox使用DOMMouseScroll,其他浏览器使用mousewheel 首先绑定一个滚动事件 //firefox使用DOMMouseScroll,其他浏览器使用mousewheel$(do ...