Max Points on a Line
来源:互联网 发布:交通大数据应用 编辑:程序博客网 时间:2024/06/08 16:19
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
1.string 用做key,如果string比较长,会耗费时间
2.在能不用map,能用单个变量操作,尽量别图方便,map查找O(log(n)),耗费空间
class Solution {public:unordered_map<double, int> ks;ostringstream os; int maxPoints(vector<Point> &points) {if(points.size() == 0)return 0;int rst = 0;for(int i = 0; i < points.size(); ++i){ks.clear();double INF = std::numeric_limits<double>::max();int m = 0;int repeat = 1;for(int j = i + 1; j < points.size(); ++j){Point tmp = points[j];if((tmp.x == points[i].x && tmp.y == points[i].y)){repeat++;continue;}double k;if(tmp.x == points[i].x){ k = INF;}else{k = (double)(tmp.y - points[i].y)/(tmp.x - points[i].x);//str = kstr(k,"");}ks[k] ++;m = max(m, ks[k]);}rst = max(rst, m + repeat);}return rst; }};
0 0
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points On a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- max points on a line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- ACM水题系列 HDOJ 1061
- 检测Python程序执行效率及内存和CPU使用的7种方法
- Apache与tomcat简介
- 基础练习二
- Hope is a good thing, maybe the best of things and no good thing ever dies !
- Max Points on a Line
- 离散数学实验课中有趣的题目
- 学习shader之前必须知道的东西之计算机图形学(一)渲染管线
- ACM水题系列 HDOJ2393
- [Unity3D]图形渲染优化、渲染管线优化、图形性能优化
- 网站页面度量与细分
- 001Android学习之旅——Android环境配置(Eclipse)
- ACM水题系列 HDOJ2629
- Android View 中view.requestLayout() 与 invalidate()