Matching heroes to enemies

Правка en1, от bigintegers, 2019-11-27 23:16:25

Given N points representing the coordinates of heroes on the coordinate plane and another N points representing the coordinates of enemies on the coordinate plane, each hero plans to battle a single enemy (the number of enemies equals the number of heroes, so nobody is ever left out).

Each hero prioritizes the enemy that is closest to them, where distance is defined as taxicab (orthogonal) distance as opposed to Euclidean distance. For example, if we have two points p, q, then the distance is NOT sqrt((p.x — q.x)^2 * (p.y — q.y)^2) but instead |p.x — q.x| + |p.y + q.y|. No two pairs of heroes and enemies will have the same distance.

What's an efficient way to make the matching? I thought about lots of graph algorithms but cannot come up with much. Maybe something with a priority queue/heap?

Thank you

Теги #heap, priority queue, #graph, #algorithms

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский bigintegers 2019-11-27 23:16:25 864 Initial revision (published)