poj-2386 dfs入门水题

poj-2386

#include 
#include 
#include 
#include 
#include 
#include 

char mapp[110][110];
using namespace std;
int n, m;
void dfs(int x, int y)
{
	mapp[x][y] = '.';
	for(int dx=-1;dx<=1;dx++)
		for (int dy = -1; dy <= 1; dy++) {
			int ddx = x + dx, ddy = y + dy;
			if (0 <= ddx&&ddx < n && 0 <= ddy&&ddy < m&&mapp[ddx][ddy] == 'W') {
				dfs(ddx, ddy);
			}
		}
	return ;
}
int main()
{
	cin >> n >> m;
	int cnt = 0;
	for (int i = 0; i < n; i++)
		cin>>mapp[i];
	for(int i=0;i

你可能感兴趣的:(dfs)