求调
查看原帖
求调
1056977
zkccjdl楼主2025/6/17 22:05

大佬求调

#include<bits/stdc++.h>
using namespace std;
int n,m,mp[35][35],dx[4]={-1,0,1,0},dy[4] = {0,-1,0,1};
void dfs(int x,int y){
	if(x < 0 || y <0 || x > n+1 || y> n+1||mp[x][y]==1){
		return ;
	}
	mp[x][y] = 0;
	for(int i = 0;i < 4;i++){
		dfs(x+dx[i],y+dy[i]);
	}
}
int main(){
	cin >> n;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			cin >> mp[i][j];
			if(mp[i][j] == 0){
				mp[i][j] = 2;
			}
		}
	}
	dfs(0,0);
	//cout << 1;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			cout << mp[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}
2025/6/17 22:05
加载中...