由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - InterviewStreet problem - Meeting Point
相关主题
amazon 1st phone interview[ job referral ] 打算申请 FACEBOOK 的进
求问G面试题,非普通的DPinterviewstreet 的chanllege #2
问个puzzle一道题:Vertical Sticks
有没有大牛看看这题目咋办[InterviewStreet] Lego Blocks (50 Points)
如何给INFINITE LOOP做UNIT TEST?[InterviewStreet] Grid Walking (Score 50 points)
Amazon 面经interviewstreet上求排列组合的题好像挺多的
An online coding test problem这次 InterviewStreet 的 Codesprint 被忽悠了,没几个公司可以申请的
一道面试改错题,求答案[InterviewStreet] XOR key (50 Points),请pass的大牛给点思路
相关话题的讨论汇总
话题: meeting话题: point话题: distance话题: sum
进入JobHunting版参与讨论
1 (共1页)
e******x
发帖数: 184
1
不知道有没有人做过这道题,题目如下
There is an infinite integer grid at which N people have their houses on.
They decide to unite at a common meeting place, which is someone's house.
From any given cell, all 8 adjacent cells are reachable in 1 unit of time.
eg: (x,y) can be reached from (x-1,y+1) in a single unit of time.
Find a common meeting place which minimises the sum of the travel times of
all the persons.
O(n^2)的解法只能过4个case,不知道怎么优化成O(n)...
我知道Manhattan distance可以转化成|x1-x2|+|y1-y2|的形式,这样如果所求点不需
要在这N点中间选就简单了,但这题还是搞不定啊~
p*g
发帖数: 141
2
where is the online test?
link please
Thanks.
p*****2
发帖数: 21240
3
又在做上边的题呀?
e******x
发帖数: 184
4
https://www.interviewstreet.com/challenges/dashboard/#problem/4e14b2cc47f78

【在 p*g 的大作中提到】
: where is the online test?
: link please
: Thanks.

e******x
发帖数: 184
5
恩,蛋疼的。

【在 p*****2 的大作中提到】
: 又在做上边的题呀?
p*****2
发帖数: 21240
6

牛。

【在 e******x 的大作中提到】
: 恩,蛋疼的。
f*****e
发帖数: 2992
7
和clustering有点像,heuristic就是先求重心,然后求离重心最近的一点。

【在 e******x 的大作中提到】
: 不知道有没有人做过这道题,题目如下
: There is an infinite integer grid at which N people have their houses on.
: They decide to unite at a common meeting place, which is someone's house.
: From any given cell, all 8 adjacent cells are reachable in 1 unit of time.
: eg: (x,y) can be reached from (x-1,y+1) in a single unit of time.
: Find a common meeting place which minimises the sum of the travel times of
: all the persons.
: O(n^2)的解法只能过4个case,不知道怎么优化成O(n)...
: 我知道Manhattan distance可以转化成|x1-x2|+|y1-y2|的形式,这样如果所求点不需
: 要在这N点中间选就简单了,但这题还是搞不定啊~

e******x
发帖数: 184
8
恩,可是不一定正确吧,怎样能保证一定找到最优点呢?

【在 f*****e 的大作中提到】
: 和clustering有点像,heuristic就是先求重心,然后求离重心最近的一点。
d*s
发帖数: 699
9
I cannot see a O(n) method here. Since the distance is evaluated as max(|x_i
-x_j|,|y_i-y_j|),the distance matrix is symmmetric and only need to
calculate a upper triangle of size N. With an OK computer N can easily be as
large as 10^4, isn't it enough?
Plus if you don't build the matrix explicitly and only keep a working array
and the minimum index, N should be able to reach 10^10-11 without an issue.
Why O(n) is a must?
p*g
发帖数: 141
10
what is your point?
A solution better than O(n^2) is highly desirable, but I thought
about it a bit, seems not that trival
check this
http://en.wikipedia.org/wiki/Geometric_median

_i
as
array
.

【在 d*s 的大作中提到】
: I cannot see a O(n) method here. Since the distance is evaluated as max(|x_i
: -x_j|,|y_i-y_j|),the distance matrix is symmmetric and only need to
: calculate a upper triangle of size N. With an OK computer N can easily be as
: large as 10^4, isn't it enough?
: Plus if you don't build the matrix explicitly and only keep a working array
: and the minimum index, N should be able to reach 10^10-11 without an issue.
: Why O(n) is a must?

e******x
发帖数: 184
11
Thanks for the wiki link~ Read it for a while. Thought "procedures that
decrease the sum of distances at each step cannot get trapped in a local
optimum" might help.
I finally made it by sorting the points by decreasing the distance to the
centroid of the points, then computing the sum until the next sum is bigger.
Have no idea if it's definitely correct, but it passed all the test cases...

【在 p*g 的大作中提到】
: what is your point?
: A solution better than O(n^2) is highly desirable, but I thought
: about it a bit, seems not that trival
: check this
: http://en.wikipedia.org/wiki/Geometric_median
:
: _i
: as
: array
: .

c*******f
发帖数: 85
12
chebyshev distance ->(rotate 45')-> manhhattan distance
1 (共1页)
进入JobHunting版参与讨论
相关主题
[InterviewStreet] XOR key (50 Points),请pass的大牛给点思路如何给INFINITE LOOP做UNIT TEST?
北京二爷你面过facebook没有?Amazon 面经
分享个有趣的 onsiteAn online coding test problem
在interviewstreet上做了几题,受打击了一道面试改错题,求答案
amazon 1st phone interview[ job referral ] 打算申请 FACEBOOK 的进
求问G面试题,非普通的DPinterviewstreet 的chanllege #2
问个puzzle一道题:Vertical Sticks
有没有大牛看看这题目咋办[InterviewStreet] Lego Blocks (50 Points)
相关话题的讨论汇总
话题: meeting话题: point话题: distance话题: sum