|
|
SPOJ Problem Set (contest)
1282. How many Islands
Problem code: COUNTISL
|
You are given a simple map of an archipelago. Can you determine how many islands it shows?
The map consists of grid squares with characters, where '#' indicates land and '.' indicates water. Two land squares belong to the same island if they are neighbouring grid squares, which means their x coordinates and y coordinates differ by at most 1.
Input
The first line of the input contains a number T ≤ 20 which indicates the number of test cases to follow.
Each test case starts with a line containing two numbers n and m (1 ≤ n,m ≤ 200), the number of rows and the number of columns of the grid, respectively. The following n lines contain m characters each and describe the map to be processed. You may assume that the map contains only characters '#' and '.', and that the border of the map consists only of water (character '.').
Output
For each test case print in a line the number of islands shown on the corresponding map in the input.
Example
Input:
2
1 1
.
6 4
....
..#.
.#..
....
.##.
....
Output:
0
2
| Added by: | Adrian Kuegel |
| Date: | 2007-01-29 |
| Time limit: | 10s
|
| Source limit: | 50000B |
| Languages: | All except: C++ 4.3.2 TCL SCALA PYTH 2.6.2 ERL TECS JS |
|
|
|
|