求助,为什么这题提交上去总是处于waiting状态
查看原帖
求助,为什么这题提交上去总是处于waiting状态
609811
accccccc楼主2022/6/8 13:06

#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <set>
#include <algorithm>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
char g[110][110];
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
int n, m;
void dfs(char c, int x, int y) {
	g[x][y] = c; //染色
	//遍历周围四个点 
	for(int i = 0; i < 4; ++i) {
		int xx = x + dx[i];
		int yy = y + dy[i];
		char tmp = (c == 'B' ? 'W' : 'B');
		if(g[xx][yy] != '.')
			continue;
		if(xx < 0 || yy < 0 || xx > n || yy > m)
			continue;
		dfs(tmp, xx, yy);
	} 
}
int main() {
	cin >> n >> m;
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			cin >> g[i][j];
		}
	}
	
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			if(g[i][j] == '.') {
				dfs('B', i, j);
			}
		}
	}
	
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			cout << g[i][j];
		}
		cout << endl; 
	}
	return 0;
} 
2022/6/8 13:06
加载中...