QUEEN ~ HINTS AND SOLUTION TO SPOJ QUESTIONS
This question requires bfs as can be clearly understood from the tag. We start doing bfs from the position of the queen. And push into the queue all the squares which can be visited by the queen from that position and update their distance by 1 and mark it visited. For eg :S..
..F
when starting from S we push into the queue positions (0,1), (0,2), (1,0), (1,1), consider 0 based indexing, update their position and mark them visited.
But while pushing into the queue just checking whether that position has been visited wont do.
Because consider the case
Read full article from QUEEN ~ HINTS AND SOLUTION TO SPOJ QUESTIONS
No comments:
Post a Comment