###### POJ No.2386-Lake Counting(算水洼）

POJ No.2386-Lake Counting(算水洼）

* * *

*W*

* * *

N=10

M=12

W********WW*

*WWW*****WWW

****WW***WW*

*********WW*

*********W**

**W******W**

*W*W*****WW*

W*W*W*****W*

*W*W******W*

**W*********

3

import java.util.Scanner;

public class LakeCounting
{
static int M, N;
static String[] field = new String[100 + 10];

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner cin = new Scanner(System.in);
System.out.print("N=");
N = cin.nextInt();
System.out.print("M=");
M = cin.nextInt();
for (int i = 0; i < N; i++)
field[i] = cin.next();
solve();
}

static void solve() {
int res = 0;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
if (field[i].charAt(j) == 'W') {
dfs(i, j);
res++;
}
System.out.println(res);
}

static void dfs(int x, int y) {
StringBuilder strBuilder = new StringBuilder(field[x]);
strBuilder.setCharAt(y, '*');
field[x]=strBuilder.toString();
int dx;
int dy;
for (dx = -1; dx <= 1; dx++)
for (dy = -1; dy <= 1; dy++) {
int nx = x + dx;
int ny = y + dy;
if (0 <= nx && nx < N && 0 <= ny && ny < M && field[nx].charAt(ny) == 'W')
dfs(nx, ny);
}
}
}

#### POJ2386-简单BFS/DFS

2016-09-15 10:51:44

#### POJ-2386--Lake Counting---DFS（深搜）

2017-08-02 16:55:49

#### poj 2386（深搜或广搜）

2014-03-07 16:51:44

#### 水洼 POJ2386 挑战程序设计竞赛

2016-09-22 20:32:49

#### poj 2386 Lake counting（深度优先搜索）

2014-09-25 20:53:05

#### POJ 2386 Lake Counting

2015-08-23 10:25:35

#### poj 2386Lake Counting（dfs）

2014-04-26 23:32:59

#### poj 2386 Lake Counting（DFS 杂这么多这种类型的水题啊。。。。）

2010-10-18 12:58:00

#### POJ NO.2386 Lake Counting(算水洼)

2016-01-19 17:24:39

#### poj 2386 Lake Counting（深搜）

2015-07-26 10:59:52

## 不良信息举报

POJ No.2386-Lake Counting(算水洼）