7.6--找过点最多的直线(CC150)
直接两个点确定一条直线。然后两两组合,再写一个看过多少个点的函数。一直更新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)的更多相关文章
- 穿点最多的直线 牛客网 程序员面试金典 C++
穿点最多的直线 牛客网 程序员面试金典 C++ 题目描述 在二维平面上,有一些点,请找出经过点数最多的那条线. 给定一个点集vectorp和点集的大小n,没有两个点的横坐标相等的情况,请返回一个vec ...
- 数据库管理——Powershell——使用Powershell脚本找出消耗最多磁盘空间的文件
原文:数据库管理--Powershell--使用Powershell脚本找出消耗最多磁盘空间的文件 原文译自: http://www.mssqltips.com/sqlservertip/2774/p ...
- CC37:穿点最多的直线
题目 在二维平面上,有一些点,请找出经过点数最多的那条线. 给定一个点集vectorp和点集的大小n,没有两个点的横坐标相等的情况,请返回一个vector,代表经过点数最多的那条直线的斜率和截距. 解 ...
- 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 ...
- 大数据面试题——如何找出访问最多的IP
问题描述: 现有海量日志数据保存在一个超大的文件中,该文件无法直接存入内存,要求从 中提取某天访问BD次数最多的IP 分析解读: 由于这个题目只关心某一天访问次数最多的IP,因此可以首先对文件进行一次 ...
- js中找string中重复项最多的字符个数
// split():字符串中的方法,把字符串转成数组. // sort():数组中的排序方法,按照ACALL码进行排序. // join():数组中的方法,把数组转换为字符串 function de ...
- C/C+面试题一:找出字符串中出现最多的字符和次数,时间复杂度小于O(n^2)
已知字符串"aabbbcddddeeffffghijklmnopqrst"编程找出出现最多的字符和次数,要求时间复杂度小于O(n^2) /********************* ...
- js--找字符串中出现最多的字符
在一个字符串中,如 'zhaochucichuzuiduodezifu',我们要找出出现最多的字符.本文章将详细说明方法思路. 先介绍两个string对象中的两个方法:indexOf()和charAt ...
- Openjudge-NOI题库-出书最多
描述 假定图书馆新进了m(10 ≤ m ≤ 999)本图书,它们都是由n(2 ≤ n ≤ 26)个作者独立或相互合作编著的.假设m本图书编号为整数(1到999),作者的姓名为字母('A'到'Z'),请 ...
随机推荐
- LVS相关学习
vi /etc/sysctl.conf net.ipv4.conf.eth0.arp_ignore = 1 net.ipv4.conf.eth0.arp_announce = 2 net.ipv4.c ...
- Python + OpenCV2 系列:1 - 配置
Python+OpenCV2+Eclipse+Windos 8.1(32bits): 最初的目的是做图像处理,opencv强大的社区支持,让我想从matlab转到opencv框架下进行试验,而Pyth ...
- Visual Studio CLR Profiler
http://blogs.msdn.com/b/dotnet/archive/2013/04/04/net-memory-allocation-profiling-with-visual-studio ...
- js取float型小数点后两位数的方法
四舍五入以下处理结果会四舍五入:' var num =2.446242342; num = num.toFixed(2); // 输出结果为 2.45 不四舍五入以下处理结果不会四舍五入:第一种, ...
- lightbox图片展示效果
1.lightbox 头部导入: <script type="text/javascript" src="../Public/Js/prototype.js&quo ...
- SmartUpLoad自动上传包
一枚默默的开发学习者 用以下代码生成文件名即可 1 package info.haowei.util; 2 3 import java.text.SimpleDateFormat; 4 import ...
- http模拟请求工具
http模拟请求工具: postman(chrome应用) Request Maker(chrome插件) Request Maker(网站:http://www.requestmaker.com/) ...
- android自定义控件(6)-详解在onMeasure()方法中如何测量一个控件尺寸
今天的任务就是详细研究一下protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)方法.如果只是说要重写什么方法有什么 ...
- JAVA日期加减运算
1.用java.util.Calender来实现 Calendar calendar=Calendar.getInstance(); calendar.setTime(new Date()) ...
- oracle 中的dual表简介与用法
Dual表是每个数据库创建时默认生成的,该表仅有一列一行. 1)分析dual表执行,如下: