解题报告:最多有多少个点在一条直线上
来源:互联网 发布:淘宝网络教育真的吗 编辑:程序博客网 时间:2024/05/02 04:26
http://www.lintcode.com/zh-cn/problem/max-points-on-a-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: /** * @param points an array of point * @return an integer */ int maxPoints(vector<Point>& points) {// Write your code here int maxc = 0;if (points.size()>2)for (int i = 0; i < points.size() - 2; i++){for (int z = i+1; z < points.size() ; z++){double x, c; if (points[z].x - points[i].x == 0){//x坐标上的垂直线int ret = 2;for (int j = i + 1; j < points.size(); j++){if (j == z)continue;if (points[j].x == points[i].x){ret++;}}maxc = max(maxc, ret);} else if (points[z].y - points[i].y == 0){//x坐标上的平行线int ret = 2;for (int j = i + 1; j < points.size(); j++){if (j == z)continue;if (points[j].y == points[i].y){ret++;}}maxc = max(maxc, ret);}else{// 1 3 2 6 x = (points[z].y - points[i].y) / (double)(points[z].x - points[i].x);c = points[i].y - points[i].x*x;int ret = 2;for (int j = i + 1; j < points.size(); j++){if (j == z)continue;if (fabs(points[j].x*x + c - points[j].y)<1e-6 ){ret++;} }maxc = max(maxc, ret);}}}else {return points.size();} return maxc;}};
0 0
- 解题报告:最多有多少个点在一条直线上
- 【LintCode】最多有多少个点在一条直线上
- LinkCode-最多有多少个点在一条直线上
- 最多有多少个点在一条直线上
- LintCode:最多有多少个点在一条直线上
- Lint_Code_最多有多少个点在一条直线上
- 最多有多少个点在一条直线上
- lintcode,最多有多少个点在一条直线上
- LintCode 最多有多少个点在一条直线上
- 最多有多少个点在一条直线上-LintCode
- lintcode最多有多少个点在一条直线上
- lintcode(186)最多有多少个点在一条直线上
- [LintCode 186] 最多有多少个点在一条直线上(Python)
- 最多有多少个点在同一条直线上
- 186.Max Points on a Line-最多有多少个点在一条直线上(中等题)
- 网易互娱笔试题----最多有多少点在一条直线上
- 二维平面上最多有多少个点在同一条直线上
- [leetcode] Max Points on a Line 判断最多有多少个点在同一条直线上
- expect用法[自动连接远程机器脚本]
- ubuntu12.04 安装VLC,在root用户下不能使用的问题
- referer详细解析
- HTML 网页截图
- HDOJ 2036 改革春风吹满地(叉乘定理)
- 解题报告:最多有多少个点在一条直线上
- 关于Eclipse
- 常见Linux发行版
- Java switch中使用string作为分支条件
- GRE写作必备句型
- CentoOS7配置samba服务
- 十个Linux中命令链接操作符的最佳实例
- 正则表达式学习笔记
- 2012年5月SAT香港真题解析