liruizhou_lihui @ 2024-08-31 22:11:08
#include<bits/stdc++.h>
using namespace std;
struct xy
{
int x;
int y;
};
int f[105][105];
int dx[12]={0,0,1,-1};
int dy[12]={1,-1,0,0};
int n;
int bfs(int x,int y)
{
queue<xy> q;
xy noww,nextt;
noww.x=x;
noww.y=y;
f[x][y]=1;
q.push(noww);
while(!q.empty())
{
noww=q.front();
q.pop();
for(int i=0;i<4;i++)
{
nextt.x=noww.x+dx[i];
nextt.y=noww.y+dy[i];
if(nextt.x>=1&&nextt.x<=n&&nextt.y>=1&&nextt.y<=n&&!f[nextt.x][nextt.y])
{
f[nextt.x][nextt.y]=2;
q.push(nextt);
}
}
}
}
int main()
{
for(int i=0;i<=31;i++)
{
f[i][0]=0;
f[i][31]=0;
f[31][i]=0;
f[0][i]=0;
}
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cin>>f[i][j];
}
}
bfs(0,0);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(f[i][j]==2)
{
cout<<"0 ";
}
else if(f[i][j]==0)
{
cout<<"2 ";
}
else
{
cout<<"1 ";
}
}
cout<<'\n';
}
return 0;
}
by __yun__ @ 2024-08-31 22:18:59
int bfs(int x,int y)
改成
void bfs(int x,int y)
by __yun__ @ 2024-08-31 22:19:42
或者关掉O2
by liruizhou_lihui @ 2024-08-31 22:33:20
@yun 谢已关