The maximum minimum distance in Manhat

Input:

  • Many points
  • Coordinates are a non-negative type integer.
  • Integer k

Output

Point P (x, y) (inside or outside the given set), the Manhattan distance to which is maximal and max(x, y) <= k

My (naive) solution:

For every (x, y) in the grid which contain given set
    BFS to find closest  point to (x, y)
    ...
return maximum;

But I believe that it works very slowly for a large grid, please help me develop a better algorithm (or code / peseudo code) to solve this problem.

Do I have to cross each (x, y)in the grid instead of a loop , I just need to loop each medianx, y

PS: Sorry for my English

EDIT:

Example:

Given P1(x1,y1), P2(x2,y2), P3(x3,y3). Find P(x,y)such that min{dist (P, P1), dist (P, P2), dist (P, P3)} is maximal

+4
3

K , , , . - , BFS, .

K , , , , . O (n log n log k)

, . , - [0, k] X [0, k], , , . , . , R, - r < R. , . , , .

, ( ) , r . " r" . r . 45 , 2r. 45 , . - , . , . , . , - . . , - [0, k] X [0, k].

, , r. , - r . , " r", . . , , - , , r.

log k . n log n n log k (n log n?) .

. .

+1

, . , , , .

, BFS . "" BFS .

2- dist [k] [k] , + inf , , P . , dist. dist , ( ), .

, , dist, . .

, .

k = 3, 1 <= x, y <= k, P1 = (1,1), P2 = (1,3), P3 = (2,2)

dist

0, + inf, + inf,

+ inf, 0, + inf,

0, + inf, + inf,

:

0, 1, + inf,

1, 0, 1,

0, 1, + inf,

:

0, 1, 2,

1, 0, 1,

0, 1, 2,

P = (3,1) (3,3)

+3

1D-, y = x y = -x. (x1, y1) (x2, y2), abs (x1-x2) + abs (y1-y2). u-v U = (1,1), V = (1, -1). : u1 = (x1-y1)/sqrt (2), v1 = (x1 + y1), u2 = (x1-y1), v2 = (x1 + y1). manhatten (u1-u2), abs (v1-v2).

. 1D u- . u-, . v.

u, v O (n), - O (n log n), - O (n).

. , (-10,0), (10,0), (0, -10), (0,10).

. O (n log n), https://en.wikipedia.org/wiki/Fortune%27s_algorithm , . psudo- wikipedia. , .

+1

Source: https://habr.com/ru/post/1534447/


All Articles