Any idea for solving O (n log n) http://www.spoj.pl/problems/GANNHAT/?

I tried the spoj problem http://www.spoj.pl/problems/GANNHAT/ , but my O (n ^ 2) solution gives TLE.Can, does anyone give me some idea about some O (n log n) solution for this problem. I can't figure out how this can be done in O (n log n) .Thanx in advance ..

+3
source share
2 answers

Use KD-Tree . This question should point you in the right direction.

+1
source

I have a solution, complexity can be O (nlogn) at best, but O (n ^ 2) at worst.

quadtrees. , , , Ai, . "", , Aj , .

Edit: , , - KD- K = 2, , 2D =)

+1

All Articles