1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| #include <bits/stdc++.h> using namespace std; typedef long long ll; #define sf(n) scanf("%d",&n) #define pf(n) printf("%d",n) #define pfc(c) printf(c) #define fi(i,s,t) for(int i=s;i<t;i++) #define fd(s,t) for(int i=s-1;i>=t;i--) #define mem(a,c) memset(a,c,sizeof(a)) const int INF=0x3f3f3f3f; const int MAX=33; int n,a[MAX][MAX],x,y; int aw[4][2]={-1,0,0,1,1,0,0,-1}; struct node{ int x ,y; node (int i,int j){ x=i;y=j; } }; bool judge2(int x,int y){ if(x<0||x>n+1||y<0||y>n+1||a[x][y]) return false; return true; } void bfs2(){ queue<node> q; q.push(node(0,0)); while(!q.empty()){ node tmp= q.front(); a[tmp.x][tmp.y]=2; q.pop(); fi(i,0,4){ int tx= tmp.x +aw[i][0],ty=tmp.y+aw[i][1]; if(judge2(tx,ty)){ q.push(node(tx,ty)); } } } } int main(){ freopen("in","r",stdin); sf(n); mem(a,0); fi(i,1,n+1) fi(j,1,n+1){ sf(a[i][j]); } bfs2(); fi(i,1,n+1){ fi(j,1,n+1){ if(a[i][j]==2) pfc("0"); else if(a[i][j]==1) pfc("1"); else if(a[i][j]==0) pfc("2"); pfc(" "); } pfc("\n"); } return 0; }
|