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

找出二维平面上处于同一条直线上的最大点数

PS: map用法。for(auto pair:slopes)pair.second

 /**
* 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) {
int len = points.size();
map<float,int> slopes;
int res=;
for(int i=;i<len;i++){
slopes.clear();
int duplicate=;
for(int j=i+;j<len;j++){
if(points[i].x==points[j].x&&points[i].y==points[j].y){
duplicate++;
}
else{
float temp= points[i].x==points[j].x? INT_MAX :(float)(points[i].y-points[j].y)/(points[i].x-points[j].x);
slopes[temp]++;
} }
res=max(res,duplicate);
for(auto pair:slopes){
res=max(res,pair.second+duplicate);
}
}
return res;
}
};

max-points-on-a-line——穷举的更多相关文章

  1. 【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 ...

  2. [LeetCode OJ] Max Points on a Line

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

  3. [LintCode] 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

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

  5. 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 on the ...

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

  7. Max Points on a Line leetcode java

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

  8. 【Max Points on a Line 】cpp

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

  9. 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 lin ...

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

随机推荐

  1. (转)TDD的iOS开发初步以及Kiwi使用入门

    本文转自“瞄神”博客 TDD的iOS开发初步以及Kiwi使用入门 测试驱动开发(Test Driven Development,以下简称TDD)是保证代码质量的不二法则,也是先进程序开发的共识.App ...

  2. java 枚举类型的使用

    应用  http://blog.csdn.net/qq_27093465/article/details/52180865 原理 http://blog.csdn.net/javazejian/art ...

  3. 四、harbor实践之初识harbor

    1 什么是Harbor harbor是VMware公司开源的企业级Registry项目,其的目标是帮助用户迅速搭建一个企业级的Docker registry 服务. 2 什么是Registry Reg ...

  4. unittest单元测试(测试报告生成)

    自动化测试执行完成之后,我们需要生成测试报告来查看测试结果,使用HTMLTestRunner模块可以直接生产Html格式的报告. 下载地址: http://tungwaiyip.info/softwa ...

  5. div的显示隐藏方法汇总

    JQuery DIV 动态隐藏和显示的方法 1. 如果在载入是隐藏: <head> <script language="javascript"> funct ...

  6. 爆炸几何之 CCPC网络赛 I - The Designer (笛卡尔定理)

    本文版权归BobHuang和博客园共有,不得转载.如想转载,请联系作者,并注明出处.   Nowadays, little hahahaha got a problem from his teache ...

  7. 2017 Multi-University Training Contest - Team 4

    日常绝望系列 Questionnaire HDU - 6075 In order to get better results in official ACM/ICPC contests, the te ...

  8. BZOJ 3130 [Sdoi2013]费用流 ——网络流

    [题目分析] 很容易想到,可以把P放在流量最大的边上的时候最优. 所以二分网络流,判断什么时候可以达到最大流. 流量不一定是整数,所以需要实数二分,整数是会WA的. [代码] #include < ...

  9. Nk 1430 Fibonacci(二分矩阵乘幂)

    AC代码: #include<iostream> using namespace std; ][]; ][]; ][]; ][]; void binary(int n) { int i,j ...

  10. 【ztree】zTree取消树节点选中的背景色

    点击树节点的时候是ztree给树加了个class:    curSelectedNode 所以最简单的清除树节点的背景色的方法是移除其有背景色的class: $(".curSelectedN ...