Na2_CuCl4 @ 2021-01-10 19:43:45
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int fg[55][55];
int n,x1,y1;
void dfs(int x,int y){
if(fg[x][y]!=0)return;
fg[x][y]=2;
dfs(x-1,y);
dfs(x,y+1);
dfs(x+1,y);
dfs(x,y-1);
}
int main(){
cin>>n>>x1>>y1;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>fg[i][j];
}
}
x1--;y1--;
dfs(x1,y1);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<fg[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
by _caiji_ @ 2021-01-10 19:46:05
dfs里面要判越界的情况
by xiaoshulin @ 2021-05-19 12:41:20
经过测试,数据很水,左上角顶点的右下角的第一个点一定在包围的区域内,直接一波dfs