@[baiyang_233](/user/750476) 输完样例后除了外面的0,中间都少了1,你看看哪里初始化啥的错了~~我没仔细看~~
by Lemon_zqp @ 2023-05-24 00:06:01
@[baiyang_233](/user/750476) 第52行为什么是==?
by Lemon_zqp @ 2023-05-24 00:08:50
改完了
```
#include<bits/stdc++.h>
#define int long long
#define il inline
using namespace std;
const int N=40;
int n,i,j;
int m[N][N],ans[N][N],vis[N][N];//m存输入,vis标记数组,ans输出数组
int dx[5]={0,1,0,-1,0},dy[5]={0,0,-1,0,1};//偏移数组
queue<int>qx,qy;
il void bfs(int x,int y){//传入坐标开始广搜
qx.push(x);
qy.push(y);
vis[x][y]=1;
while(!qx.empty()){
int xx=qx.front(),yy=qy.front();
qx.pop(),qy.pop();
for(i=1;i<=4;i++){//四向偏移
int xxx=xx+dx[i],yyy=yy+dy[i];
if(vis[xxx][yyy]==0&&m[xxx][yyy]==0&&xxx>=1&&xxx<=n&&yyy>=1&&yyy<=n){//判定
vis[xxx][yyy]=1;
qx.push(xxx);
qy.push(yyy);
}
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);//朴实の加速码
cin>>n;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
cin>>m[i][j];
ans[i][j]=m[i][j];//同时保存ans和m
if(m[i][j]==1)
vis[i][j]=1;//如果是墙vis提前标记1
}
}
for(i=1;i<=n;i++){//四个边界搜
if(vis[1][i]==0)
bfs(1,i);
if(vis[n][i]==0)
bfs(n,i);
if(vis[i][1]==0)
bfs(i,1);
if(vis[i][n]==0)
bfs(i,n);
}
for(i=1;i<=n;i++){//更新ans
for(j=1;j<=n;j++){
if(vis[i][j]==0)
ans[i][j]=2;
}
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
cout<<ans[i][j]<<' ';
}
cout<<"\n";
}
return 0;
}
```
by Lemon_zqp @ 2023-05-24 00:09:34
@[Lemon_zqp](/user/551630) 谢谢大佬(磕
手瞎了真的,赋值能打成连等qwq
by Hf_Poem @ 2023-05-24 21:22:20
原来早期白羊连dfs都不会
by zyh0516_lucky @ 2023-10-08 21:13:51