avatar
e*x
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点中间选就简单了,但这题还是搞不定啊~
avatar
f*e
2
avatar
p*g
3
where is the online test?
link please
Thanks.
avatar
H*g
4
这个厉害
avatar
p*2
5
又在做上边的题呀?
avatar
e*x
7
恩,蛋疼的。

【在 p*****2 的大作中提到】
: 又在做上边的题呀?
avatar
p*2
8

牛。

【在 e******x 的大作中提到】
: 恩,蛋疼的。
avatar
f*e
9
和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点中间选就简单了,但这题还是搞不定啊~

avatar
e*x
10
恩,可是不一定正确吧,怎样能保证一定找到最优点呢?

【在 f*****e 的大作中提到】
: 和clustering有点像,heuristic就是先求重心,然后求离重心最近的一点。
avatar
d*s
11
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?
avatar
p*g
12
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?

avatar
e*x
13
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
: .

avatar
c*f
14
chebyshev distance ->(rotate 45')-> manhhattan distance
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。