Question: You are mapping a faraway planet using a satellite. The planet's surface can be modeled as a grid. Your satellite has captured an image of

You are mapping a faraway planet using a satellite. The planet's surface can be modeled as a grid. Your satellite has captured an image of the surface. Each grid square is either land (denoted as 'L'), water (denoted as W), or covered by clouds ('C). Clouds mean that the surface could either be land or water, but you can't tell. An island is a maximal region of land where every grid cell in the island is reachable from every other by a path that only goes up, down, left or right. Given an image, determine the minimum number of islands that is consistent with the given information Input Format The first line of input contains two integers, n and m, which are the height and width of the image. The next n lines will each contain exactly m characters, consisting only of 'L', 'w and 'C, as explained above. Constraints Output Format Print one line of output containing an integer denoting the minimum number of islands possible. Sample Input o 4 5 ccocc CCOCC Sample Output 0 Sample Input 1 3 2 Sample Output 1 Sample Input 2 10 10 CLWLWWLWC CWLWLWLWLC wwwwwLLWWw LLWLLWWLLL Sample Output 2 Sample Input 3 10 10 LcocCCcOCC cccCCcCCC COOCOCCOL LWLW Sample Output 3 12 You are mapping a faraway planet using a satellite. The planet's surface can be modeled as a grid. Your satellite has captured an image of the surface. Each grid square is either land (denoted as 'L'), water (denoted as W), or covered by clouds ('C). Clouds mean that the surface could either be land or water, but you can't tell. An island is a maximal region of land where every grid cell in the island is reachable from every other by a path that only goes up, down, left or right. Given an image, determine the minimum number of islands that is consistent with the given information Input Format The first line of input contains two integers, n and m, which are the height and width of the image. The next n lines will each contain exactly m characters, consisting only of 'L', 'w and 'C, as explained above. Constraints Output Format Print one line of output containing an integer denoting the minimum number of islands possible. Sample Input o 4 5 ccocc CCOCC Sample Output 0 Sample Input 1 3 2 Sample Output 1 Sample Input 2 10 10 CLWLWWLWC CWLWLWLWLC wwwwwLLWWw LLWLLWWLLL Sample Output 2 Sample Input 3 10 10 LcocCCcOCC cccCCcCCC COOCOCCOL LWLW Sample Output 3 12
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
