70分,救命!
查看原帖
70分,救命!
593403
PanDaoxi楼主2022/9/5 13:55

7~9点过不了,求助!大佬们救救我啊,找不到问题?

// Author:PanDaoxi
#include <bits/stdc++.h>
using namespace std;
const int inf = 101;
int n, m, ans,
	fx[9] = {-1, -1, -1, 0, 1, 1, 1, 0,},
	fy[9] = {-1, 0, 1, 1, 1, 0, -1, -1,};
bool a[inf][inf];
void dfs(int x, int y){
	a[x][y] = false;
	for(int i=1; i<=8; i++){
		int xx = x + fx[i],
			yy = y + fy[i];
		if(
			xx >= 1 && xx <= n &&
			yy >= 1 && yy <= m &&
			a[xx][yy]
		) dfs(xx, yy);
	}
}
int main(){
	cin >> n >> m;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			char c;
			cin >> c;
			a[i][j] = c == 'W';
		}
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			if(a[i][j]){
				dfs(i, j);
				ans++;
			}
		}
	}
	cout << ans;
	return 0;
}
2022/9/5 13:55
加载中...