Finding unreachable sections of a 2D map

Posted by dada on Stack Overflow See other posts from Stack Overflow or by dada
Published on 2010-04-18T14:31:54Z Indexed on 2010/04/18 14:53 UTC
Read the original article Hit count: 316

Filed under:
|

I don't want you to solve this problem for me, i just want to ask for some ideas.

This is the input below, and it represents a map. The 'x' represents land, and the dots - water. So with the 'x' you can represent 'islands' on the map.

xxx.x...xxxxx        
xxxx....x...x        
........x.x.x        
..xxxxx.x...x       
..x...x.xxx.x        
..x.x.x...x..        
..x...x...xxx        
...xxxxxx....        
x............ 

As you can see, there are some islands which are closed, i.e. if some boat is inside its territory, it won't be able to get out, for ex:

..xxxxx.     
..x...x.        
..x.x.x.        
..x...x.
..xxxxx.

And there are some open islands which is possible to get out of them, ex:

.xxxxx        
.x...x        
.x.x.x        
.xxx.x       

The problem is this: For a given NxM map like those above, calculate howm any of the islands are open, and how many are closed.

I repeat: I don't want you to solve it, just need some sugestions, ideas for solving. thanks

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about problem-solving