直接两个点确定一条直线。然后两两组合,再写一个看过多少个点的函数。一直更新max就行。


import java.util.Arrays;

public class Solution {

    public static void main(String[] args){
Point[] a = {new Point(0,0),new Point(1,1),new Point(2,2),new Point(0,3)}; System.out.println(Arrays.toString(getLine(a,4)));
}
public static double[] getLine(Point[] p, int n){
double[] resLast = new double[2];
//思路:两个点得到一条直线。
int max = 0;
for(int i = 0; i < p.length; i++){
for(int j = i + 1; j < p.length; j++){
double[] res = new double[2];
//把直线求出来。并算出个数
int num = 0;
res[0] = (p[j].y - p[i].y) * 1.0 / (p[j].x - p[i].x);
res[1] = p[j].y - res[0] *p[j].x;
num = num(p,res );
if(num > max){
max = num;
resLast = res;
}
}
} return resLast;
} public static int num(Point[] p, double[] res){
int num = 0;
for(int i = 0; i < p.length; i++){
if(p[i].y == (p[i].x * res[0] + res[1])){
num++;
}
} return num;
} } class Point {
int x;
int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public Point() {
this.x = 0;
this.y = 0;
}
}

 

7.6--找过点最多的直线(CC150)的更多相关文章

  1. 穿点最多的直线 牛客网 程序员面试金典 C++

    穿点最多的直线 牛客网 程序员面试金典 C++ 题目描述 在二维平面上,有一些点,请找出经过点数最多的那条线. 给定一个点集vectorp和点集的大小n,没有两个点的横坐标相等的情况,请返回一个vec ...

  2. 数据库管理——Powershell——使用Powershell脚本找出消耗最多磁盘空间的文件

    原文:数据库管理--Powershell--使用Powershell脚本找出消耗最多磁盘空间的文件 原文译自: http://www.mssqltips.com/sqlservertip/2774/p ...

  3. CC37:穿点最多的直线

    题目 在二维平面上,有一些点,请找出经过点数最多的那条线. 给定一个点集vectorp和点集的大小n,没有两个点的横坐标相等的情况,请返回一个vector,代表经过点数最多的那条直线的斜率和截距. 解 ...

  4. B. Amr and The Large Array(Codeforces Round #312 (Div. 2)+找出现次数最多且区间最小)

    B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes input st ...

  5. 大数据面试题——如何找出访问最多的IP

    问题描述: 现有海量日志数据保存在一个超大的文件中,该文件无法直接存入内存,要求从 中提取某天访问BD次数最多的IP 分析解读: 由于这个题目只关心某一天访问次数最多的IP,因此可以首先对文件进行一次 ...

  6. js中找string中重复项最多的字符个数

    // split():字符串中的方法,把字符串转成数组. // sort():数组中的排序方法,按照ACALL码进行排序. // join():数组中的方法,把数组转换为字符串 function de ...

  7. C/C+面试题一:找出字符串中出现最多的字符和次数,时间复杂度小于O(n^2)

    已知字符串"aabbbcddddeeffffghijklmnopqrst"编程找出出现最多的字符和次数,要求时间复杂度小于O(n^2) /********************* ...

  8. js--找字符串中出现最多的字符

    在一个字符串中,如 'zhaochucichuzuiduodezifu',我们要找出出现最多的字符.本文章将详细说明方法思路. 先介绍两个string对象中的两个方法:indexOf()和charAt ...

  9. Openjudge-NOI题库-出书最多

    描述 假定图书馆新进了m(10 ≤ m ≤ 999)本图书,它们都是由n(2 ≤ n ≤ 26)个作者独立或相互合作编著的.假设m本图书编号为整数(1到999),作者的姓名为字母('A'到'Z'),请 ...

随机推荐

  1. PyCharm 教程(四)显示行号

    PyCharm 教程(四)显示行号 在PyCharm 里,显示行号有两种办法: 1,临时设置.右键单击行号处,选择 Show Line Numbers. 但是这种方法,只对一个文件有效,并且,重启Py ...

  2. Xcode打印frame id

    开启 打开终端输入三条命令: . touch ~/.lldbinit . echo display @import UIKit >> ~/.lldbinit . echo target s ...

  3. Jbuilder 2008安装及破解

    1.下载Jbuilder及破解包 2.安装: 1>点击install 2> 选择第一项: 3>同意协议: 4>选择安装目录 5>选择服务器 6>选择默认 7> ...

  4. owin要跑起来

    必须安装 Microsoft.Owin.Host.SystemWeb

  5. HTTP错误404.13 - Not Found 请求筛选模块被配置为拒绝超过请求内容长度的请求

    http://www.cnblogs.com/JKqingxinfeng/archive/2012/10/29/2744663.html HTTP错误404.13 - Not Found 请求筛选模块 ...

  6. struts.xml框架

    1.首先在.jsp文件中<form action="/项目名称/login" method="post"> 2.然后浏览器会访问struts.xml ...

  7. 修改hosts

  8. Java读取txt文件,计算2011年9月份的通话时间

    public class test2 { /** * @param args * @throws IOException */ public static void main(String[] arg ...

  9. java.lang.reflect.Field

    java.lang.reflect.Field 一.Field类是什么 Field是一个类,位于java.lang.reflect包下. 在Java反射中 Field类描述的是 类的属性信息,通俗来讲 ...

  10. HTML5+ 学习笔记3 storage.增删改查

    //插入N条数据 function setItemFun( id ) { //循环插入100调数据 var dataNum = new Number(id); for ( var i=0; i< ...