Monday, March 31, 2014

SPOJ 12323. Minimum Knight Moves!!!

http://www.spoj.com/problems/NAKANJ/

 There are lots of ways to solve this, BFS recursion, DFS dynamic. I suggest using thee BFS (If you need more info on BFS go here) approach, it is simpler to understand but harder to implement. Just keep a queue and push the coordinates of the first cell to it, every time you take out an element check all of the 8 neighbors that cell has and add them to the queue , also don't forget to mark all the visited cells so that you won't have to visit them again and again.Check out the source code for a better understanding.


       DOWNLOAD THE FULL SOURCE CODE




No comments:

Post a Comment