ZHOUJIECHEN @ 2023-06-01 21:23:14
using namespace std;
int a[330][330];
int b[330][330];
int d[330][330];
struct c{
int x,y;
};
int n,m,ans;
queue<c> q;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
scanf("%1d",&a[j][i]);
}
}
for(int i=0;i<=n+1;i++)
{
for(int j=0;j<=n+1;j++)
{
if(a[j][i]==1)
{
b[j][i]=1;
}
else
{
b[j][i]=2;
}
}
}
c tmp={0,0};
q.push(tmp);
d[0][0]=-1;
b[0][0]=0;
while(!q.empty())
{
int ux=q.front().x;
int uy=q.front().y;
q.pop();
if(ux>=n&&uy>=n)
{
break;
}
if(a[ux+1][uy]==0&&d[ux+1][uy]==0)
{
c tmp={ux+1,uy};
q.push(tmp);
b[ux+1][uy]=0;
d[ux+1][uy]=-1;
}
if(a[ux-1][uy]==0&&d[ux-1][uy]==0)
{
c tmp={ux-1,uy};
q.push(tmp);
b[ux-1][uy]=0;
d[ux-1][uy]=-1;
}
if(a[ux][uy+1]==0&&d[ux][uy+1]==0)
{
c tmp={ux,uy+1};
q.push(tmp);
b[ux][uy+1]=0;
d[ux][uy+1]=-1;
}
if(a[ux][uy-1]==0&&d[ux][uy-1]==0)
{
c tmp={ux,uy-1};
q.push(tmp);
b[ux][uy-1]=0;
d[ux][uy-1]=-1;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cout<<b[j][i]<<" ";
}
cout<<endl;
}
}```
by ZHOUJIECHEN @ 2023-06-02 21:47:01
解出来了