, , O(n) , .
R , R x y. , . c :
c.x<=p.x && p.x<=c.x+R && c.y<=p.y && p.y<=c.y+R
(, ).
/ , . /, -.
. :

. . 7-9 . , , , 8 .
, p (x, y), N[p] p R, Np[y][x] (x, y), N[p] :
N[p] = Np[y][x]+
Np[y][x-1]+
Np[y-1][x-1]+
Np[y-1][x]+
Np[y-1][x+1]+
Np[y][x+1]+
Np[y+1][x+1]+
Np[y+1][x]+
Np[y+1][x-1]
, , maxheap O(n) (, make_heap). , O (log n) , .
O (log n + k) ( ), , . best_found N[p].
. N[best_found], . .
, :

(., , - , , FIFO). , .
, :

, : , , . , , .
You could and should use a similar restrictive technique in conjunction with mcdowella answers ; however, his answer does not provide a good place to start the search, so you can spend a lot of time exploring items with low cost.
source
share