其实我也纳闷啊,为什么这么长啊。。。。看DISCUSS发现从R到A WA,从A到R就AC了,果真是。。。
1 #include2 #include 3 char p[201][201]; 4 int o[201][201],x[100000],y[100000]; 5 int time[100000]; 6 int a[4] = { 0,0,1,-1}; 7 int b[4] = { 1,-1,0,0}; 8 int main() 9 {10 int i,j,k,n,m,start,end,air,aic,num,z;11 while(scanf("%d%d%*c",&n,&m)!=EOF)12 {13 memset(o,0,sizeof(o));14 memset(time,0,sizeof(o));15 for(i = 0; i <= n-1; i ++)16 gets(p[i]);17 k = 0;18 num = 0;19 z = 0;20 for(i = 0; i <= n; i ++)21 {22 for(j = 0; j <= m-1; j ++)23 {24 if(p[i][j] == 'a')25 {26 air = i;27 aic = j;28 }29 else if(p[i][j] == '#')30 {31 o[i][j] = 1;32 }33 else if(p[i][j] == 'x')34 {35 o[i][j] = 2;36 }37 }38 }39 start = end = 0;40 x[0] = air;41 y[0] = aic;42 while(start <= end)43 {44 j = 1;45 for(i = start;i <= end;i ++)46 {47 if(p[x[i]][y[i]] == 'r')48 {49 z = 1;50 break;51 }52 }53 if(z) break;54 for(i = start; i <= end; i ++)55 {56 if(time[i] == 0)57 {58 for(k = 0; k <= 3; k ++)59 {60 if(x[i]+a[k]>=0&&x[i]+a[k]<=n-1&&y[i]+b[k]>=0&&y[i]+b[k]<=m-1)61 {62 if(o[x[i]+a[k]][y[i]+b[k]] == 0)63 {64 o[x[i]+a[k]][y[i]+b[k]] = 1;65 x[j+end] = x[i]+a[k];66 y[j+end] = y[i]+b[k];67 j ++;68 }69 else if(o[x[i]+a[k]][y[i]+b[k]] == 2)70 {71 o[x[i]+a[k]][y[i]+b[k]] = 1;72 time[j+end] = 1;73 x[j+end] = x[i]+a[k];74 y[j+end] = y[i]+b[k];75 j ++;76 }77 }78 }79 }80 else81 {82 time[j+end] = time[i] - 1;83 x[j+end] = x[i];84 y[j+end] = y[i];85 j ++;86 }87 }88 start = end + 1;89 end = end + j -1;90 num ++;91 }92 if(z)93 printf("%d\n",num);94 else95 printf("Poor ANGEL has to stay in the prison all his life.\n");96 }97 return 0;98 }