Sunday, March 30, 2014

1706. Queens, Knights and Pawns

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

 This task is a good task of implementation, there is not much to explain here you need to keep an array fill the given figures and then loop over the array, whenever you find a figure in there you need to check all the cells that figure can attack, for knight its simple you need to check only 8 cells , for the queen I suggest writing a recursive function which will start from a certain cell and move in a certain direction. Here is how it will look like
void rec( int x, int y, int px, int py)
where px and py show the number which we after being added to x and y will give you the position of the next cell for example px=1 and py=1 will lead you to south east. Check the source code for a better understanding


       DOWNLOAD THE FULL SOURCE CODE

No comments:

Post a Comment