先帮你排个版。。。
```
include <iostream>
include <queue>
using namespace std;
int n,a[31][31];
int xx[4]= {0,0,1,-1},yy[4]= {1,-1,0,0};
struct xy {
int x,y;
};
queue<xy> tu;
void BFS() {
while(!tu.empty()) {
xy p=tu.front();
tu.pop();
a[p.x][p.y]=2;
for(int i=0; i<4; i++) {
xy q;
q.x=p.x+xx[i];
q.y=p.y+yy[i];
if(!a[q.x][q.y]) tu.push(q);
}
}
return;
}
int main() {
xy top;
cin>>n;
for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) {
cin>>a[i][j];
if(a[i][j]==0&&a[i-1][j]==1&&a[i][j-1]==1&&tu.empty()) {
top.x=i;
top.y=j;
tu.push(top);
}
}
BFS();
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
cout<<a[i][j];
if (j!=n) cout<<" ";
}
if(i!=n) cout<<endl;
}
return 0;
}
```
by Siyuan @ 2018-03-25 08:03:58
@[siyuan](/space/show?uid=49725) 啊。。抱歉,昨天是在手机上传的
by KryptonAu @ 2018-03-25 10:53:56