Problem K
Time Limit : 2000/1000ms (Java/Other) Memory Limit :65536/32768K (Java/Other)
Total Submission(s) : 2 Accepted Submission(s) : 1
Problem Description
The GeoSurvComp geologicsurvey company is responsible for detecting underground oil deposits.GeoSurvComp works with one large rectangular region of land at a time, andcreates a grid that divides the land into numerous square plots. It thenanalyzes each plot separately, using sensing equipment to determine whether ornot the plot contains oil. A plot containing oil is called a pocket. If twopockets are adjacent, then they are part of the same oil deposit. Oil depositscan be quite large and may contain numerous pockets. Your job is to determinehow many different oil deposits are contained in a grid. <br>
Input
The input file contains one ormore grids. Each grid begins with a line containing m and n, the number of rowsand columns in the grid, separated by a single space. If m = 0 it signals theend of the input; otherwise 1 <= m <= 100 and 1 <= n <= 100.Following this are m lines of n characters each (not counting the end-of-linecharacters). Each character corresponds to one plot, and is either `*',representing the absence of oil, or `@', representing an oil pocket.<br>
Output
For each grid, output thenumber of distinct oil deposits. Two different pockets are part of the same oildeposit if they are adjacent horizontally, vertically, or diagonally. An oildeposit will not contain more than 100 pockets.<br>
Sample Input
1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0
Sample Output
0
1
2
2
T算法分析:
细胞的变形,一开始想复杂l,想会不会有两个细胞相同,但考虑这一点反而过不了了,不考虑也就过了。
代码实现: