由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - interview question:找包含点数最多的线段
相关主题
除了某家之外,讨论个F的面试题吧,merge 2D interval找工作总结(CS)
Interview questions: points lie on same line再提两个问题
Caeercup150 原题:Find a line passes most pointsMS 电面面经,攒人品
问一个G公司的题Another interview problem ~
被烙印阴了: draw a line across two points二维平面6000点,求穿过最多点的线
Leetcode 新题max points on a lineCS interview question
Max points on a lineAsk a google interview question(2)
某公司面试经历H1B cap 预计 12/3 到12/7 用完
相关话题的讨论汇总
话题: int话题: slope话题: hashcode话题: interview话题: lines
进入JobHunting版参与讨论
1 (共1页)
k*j
发帖数: 153
1
Given a two dimensional graph with points on it, find a line which passes
the most number of points.
这是在cracking coding interview书里(10.6)的一题。书里是用hash的方法。
public int hashCode(){
int s1= (int)(slope*1000);
int in = (int)(intercept*1000);
return s1 | in;
}
但我一直不明白,如果是x = x1,也就是slope = infinite的情况,如何求这个
hashcode呢?因为infite是inf, 乘上1000 = ?
k*j
发帖数: 153
2
顶一下。期待同学解答一下
b*******8
发帖数: 37364
3
对斜率无穷的竖线,大不了专门扫一次特殊处理,O(N)时间。
P**********c
发帖数: 3417
4
斜率无穷的直线,书上没有把slope存成无穷,初始值是多少就是多少, Java里应该是
默认为0。你要是用C++写的话,可以在Line的constructor里面的else{}部分把slope设
成0就没问题了.

【在 k*j 的大作中提到】
: Given a two dimensional graph with points on it, find a line which passes
: the most number of points.
: 这是在cracking coding interview书里(10.6)的一题。书里是用hash的方法。
: public int hashCode(){
: int s1= (int)(slope*1000);
: int in = (int)(intercept*1000);
: return s1 | in;
: }
: 但我一直不明白,如果是x = x1,也就是slope = infinite的情况,如何求这个
: hashcode呢?因为infite是inf, 乘上1000 = ?

l***i
发帖数: 1309
5
You have at most (n choose 2)=n^2 lines for each pair of points. Represent
each line as A*x+B*y=C.
Now sort the triples for all lines. Lines coincide will have same (A,B,C) so
count them. This is O(n^2logn). If you have a magic hash function, you can
get O(n^2) assume you map each distinct triple to a unique bucket.
1 (共1页)
进入JobHunting版参与讨论
相关主题
H1B cap 预计 12/3 到12/7 用完被烙印阴了: draw a line across two points
收到据信了,随便写点Leetcode 新题max points on a line
G电面Max points on a line
给一堆points, 找到所有给定长度的正方形某公司面试经历
除了某家之外,讨论个F的面试题吧,merge 2D interval找工作总结(CS)
Interview questions: points lie on same line再提两个问题
Caeercup150 原题:Find a line passes most pointsMS 电面面经,攒人品
问一个G公司的题Another interview problem ~
相关话题的讨论汇总
话题: int话题: slope话题: hashcode话题: interview话题: lines