请问这串代码为什么会RE
查看原帖
请问这串代码为什么会RE
1533940
hola0826楼主2024/10/24 11:43
#include <iostream>
using namespace std;
int a[100][100],b[100][100];
int d[4][2] = { {1,0},{-1,0},{0,1},{0,-1} };
int n;
void dfs(int x, int y) {
	if (x<0 || x>n + 1 || y < 0 || y>n + 1)return;
	for (int i = 0; i <= 3; i++) {
		int xx = x + d[i][0];
		int yy = y + d[i][1];
		if (a[xx][yy] == 0) {
			a[xx][yy] = -1;
			b[xx][yy] = a[xx][yy];
			dfs(xx, yy);
			a[xx][yy] = 0;
		}
	}
}
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			b[i][j] = a[i][j];
		}
	}
	dfs(0, 0);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (b[i][j] == -1) {
				b[i][j] = 0;
				cout << b[i][j];
			}
			else if (b[i][j] == 0) {
				b[i][j] = 2;
				cout << b[i][j];
			}
			else {
				cout << b[i][j];
			}
		}
		cout << endl;
	}
	return 0;
}
2024/10/24 11:43
加载中...