```cpp
[codec ]#include<stdio.h>
#include<stdlib.h>
#include<string.h>
const int dmax=100;
int d[5][2]={{0,0},{1,0},{0,1},{-1,0},{0,-1}},x1,y1,x2,y2,tx,ty,head,tail,flag;
int a[dmax][dmax],p[dmax][dmax];
struct node{
int x,y;
int s;
node(){
x=y=0;
s=0;
}
};
struct node q[dmax*dmax];
int main(){
int i,j,k,m,n;
scanf("%d",&n);
x1=y1=n;
x2=y2=1;
for (i=0;i<=n+1;i++)
a[0][i]=a[n+1][i]=1;
for (i=0;i<=n+1;i++)
a[i][0]=a[i][n+1]=1;
for (i=1;i<=n;i++)
for (j=1;j<=n;j++){
scanf("%d",&a[i][j]);
if (a[i][j]==1){
if (i<x1)
x1=i;
if (j<y1)
y1=j;
if (i>x2)
x2=i;
if (j>x2)
y2=j;
}
}
int f=0,l=1;
int u,v;
for (i=1;i<=n;i++)
for (j=1;j<=n;j++){
if (i>x1 && j>y1 && i<x2 && j<x2 && a[i][j]==0 && !p[i][j]){
q[l].x=i;
q[l].y=j;
a[i][j]=2;
p[i][j]=1;
while (f<l){
f++;
for (k=1;k<=4;k++){
tx=q[f].x+d[k][0];
ty=q[f].y+d[k][1];
if (p[tx][ty]==0 && a[tx][ty]!=1){
q[++l].x=tx;
q[l].y=ty;
q[l].s=q[f].s+1;
p[tx][ty]=1;
a[tx][ty]=2;
}
}
}
for (u=1;u<=n;u++,puts(""))
for (v=1;v<=n;v++)
printf("%d ",a[u][v]);
return 0;
}
}
return 0;
}
```
[codec /]
哪里错了?
by shenxingyu @ 2015-09-18 13:01:41
[codec]
```cpp
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
const int dmax=100;
int d[5][2]={{0,0},{1,0},{0,1},{-1,0},{0,-1}},x1,y1,x2,y2,tx,ty,head,tail,flag;
int a[dmax][dmax],p[dmax][dmax];
struct node{
int x,y;
int s;
node(){
x=y=0;
s=0;
}
};
struct node q[dmax*dmax];
int main(){
int i,j,k,m,n;
scanf("%d",&n);
x1=y1=n;
x2=y2=1;
for (i=0;i<=n+1;i++)
a[0][i]=a[n+1][i]=1;
for (i=0;i<=n+1;i++)
a[i][0]=a[i][n+1]=1;
for (i=1;i<=n;i++)
for (j=1;j<=n;j++){
scanf("%d",&a[i][j]);
if (a[i][j]==1){
if (i<x1)
x1=i;
if (j<y1)
y1=j;
if (i>x2)
x2=i;
if (j>x2)
y2=j;
}
}
int f=0,l=1;
int u,v;
for (i=1;i<=n;i++)
for (j=1;j<=n;j++){
if (i>x1 && j>y1 && i<x2 && j<x2 && a[i][j]==0 && !p[i][j]){
q[l].x=i;
q[l].y=j;
a[i][j]=2;
p[i][j]=1;
while (f<l){
f++;
for (k=1;k<=4;k++){
tx=q[f].x+d[k][0];
ty=q[f].y+d[k][1];
if (p[tx][ty]==0 && a[tx][ty]!=1){
q[++l].x=tx;
q[l].y=ty;
q[l].s=q[f].s+1;
p[tx][ty]=1;
a[tx][ty]=2;
}
}
}
for (u=1;u<=n;u++,puts(""))
for (v=1;v<=n;v++)
printf("%d ",a[u][v]);
return 0;
}
}
return 0;
}
```
[/codec]
哪里错了
by shenxingyu @ 2015-09-18 13:02:20