标签:
1 5 5 14 S*#*. .#... ..... ****. ...#. ..*.P #.*.. ***.. ...*. *.#..
YES
//0MS 1464K #include<stdio.h> #include<string.h> #include<queue> using namespace std; int n,m,t,sx,sy,ex,ey,sz,ez; int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}}; int vis[2][17][17]; char g[2][17][17]; struct sa { int x,y,z,s; }; int bfs() { queue<sa>q; memset(vis,0,sizeof(vis)); sa now,next; now.z=0;now.x=0;now.y=0;now.s=0; vis[sz][sx][sy]=1; q.push(now); while(!q.empty()) { now=q.front(); q.pop(); if(now.z==ez&&now.x==ex&&now.y==ey) { if(now.s<=t)return 1; return -1; } for(int i=0;i<4;i++) { int xx=now.x+dir[i][0]; int yy=now.y+dir[i][1]; int zz=now.z; if(xx>=0&&xx<n&&yy>=0&&yy<m&&!vis[zz][xx][yy]&&g[zz][xx][yy]!='*') { vis[zz][xx][yy]=1; next.z=zz;next.x=xx;next.y=yy;next.s=now.s+1; if(g[zz][xx][yy]!='#') q.push(next); else { if(now.z==1&&!vis[0][xx][yy]&&g[0][xx][yy]!='*') { if(g[0][xx][yy]!='#')next.z=0,q.push(next); } if(now.z==0&&!vis[1][xx][yy]&&g[1][xx][yy]!='*') { if(g[1][xx][yy]!='#')next.z=1,q.push(next); } } } } } return -1; } int main() { //freopen("in.txt","r",stdin); int T; scanf("%d",&T); while(T--) { scanf("%d%d%d",&n,&m,&t); for(int z=0;z<2;z++) for(int i=0;i<n;i++) { scanf("%s",g[z][i]); for(int j=0;j<m;j++) { if(g[z][i][j]=='S'){sx=i;sy=j;sz=z;} if(g[z][i][j]=='P'){ex=i;ey=j;ez=z;} } } if(bfs()==-1)printf("NO\n"); else printf("YES\n"); } return 0; }
标签:
原文地址:http://blog.csdn.net/crescent__moon/article/details/44245455