Monday, April 7, 2014

SPOJ 12880. Sheep (KOZE)

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

  We will solve this using BFS or DFS  We need to keep a boolean array called MARK[N][M] where MARK[i][j] shows whether we visited that cell or no. Thu function of our BFS or DFS is to cover all the cells of the current sector and also keeping track of the number of sheep and wolves . When the BFS\DFS is  done with covering the sectors we  will check the conditions and see if the sheep defeated the wolves or they lost or none of them. The way we are going to cover our sectors is the following. We need to loop over our MARK array and see if there is a cell which we haven;t visited and that cell is not a fence then we should start our function which will cover all the cells in that sector. also check the source code for a better understanding.


       DOWNLOAD THE FULL SOURCE CODE

No comments:

Post a Comment