空中漫步# Joke - 肚皮舞运动
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点中间选就简单了,但这题还是搞不定啊~
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点中间选就简单了,但这题还是搞不定啊~