20pts求助
查看原帖
20pts求助
1757986
Cole_Palmer楼主2025/6/21 13:50
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 1e2 + 5;
ll n, m;
char c[MAXN][MAXN];
ll dx[10] = {0, -1, -1, -1, 0, 0, 1, 1, 1};
ll dy[10] = {0, -1, 0, 1, -1, 1, -1, 0, 1};
void dfs(ll x, ll y) {
	ll xx, yy;
	c[x][y] = '.';
	cout << endl;
	cout << "x:" << x << " y:" << y << endl;
	for (ll i = 1; i <= 8; ++i) {
		xx = x + dx[i], yy = y + dy[i];
		if (xx < 1 || xx > n || yy < 1 || yy > m || c[x][y] == '.') continue;
		c[xx][yy] = '.';
		dfs(xx, yy);
	}
}
int main() {
	cin >> n >> m;
	for (ll i = 1; i <= n; ++i) {
		for (ll j = 1; j <= m; ++j) {
			cin >> c[i][j];
		}
	}
	ll cnt = 0;
	for (ll i = 1; i <= n; ++i) {
		for (ll j = 1; j <= m; ++j) {
			if (c[i][j] == 'W') {
				cnt++;
				dfs(i, j);
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

不明白哪里错了

2025/6/21 13:50
加载中...