标签:des style blog http io ar color os sp
1 5 5 14 S*#*. .#... ..... ****. ...#. ..*.P #.*.. ***.. ...*. *.#..
YES
#include<stdio.h> #include<queue> #include<iostream> using namespace std; struct node { int z,x,y,t; }; int n,m,t; char map[2][15][15]; int bfs(int x,int y,int z) { queue<node>q; node p,tp; int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}}; p.x=x; p.y=y; p.z=z; p.t=0; if(t)// q.push(p); map[z][x][y]='*'; while(!q.empty()) { p=q.front(); q.pop(); for(int e=0;e<4;e++) { tp=p; tp.x+=dir[e][0]; tp.y+=dir[e][1]; tp.t++; if(tp.x>=0&&tp.x<n&&tp.y>=0&&tp.y<m&&map[tp.z][tp.x][tp.y]!='*') { if(map[tp.z][tp.x][tp.y]=='#') { map[tp.z][tp.x][tp.y]='*'; tp.z^=1; if(map[tp.z][tp.x][tp.y]=='#') map[tp.z][tp.x][tp.y]='*'; if(map[tp.z][tp.x][tp.y]=='*') continue; } if(map[tp.z][tp.x][tp.y]=='P') return t; map[tp.z][tp.x][tp.y]='*'; if(tp.t<t) q.push(tp); } } } return 0; } int main() { int c,x,y,z; scanf("%d",&c); while(c--) { scanf("%d%d%d",&n,&m,&t); for(int j=0;j<n;j++) { scanf("%s",map[0][j]); for(int e=0;e<m;e++) if(map[0][j][e]=='S') x=j,y=e,z=0; } for(int j=0;j<n;j++) { scanf("%s",map[1][j]); for(int e=0;e<m;e++) if(map[1][j][e]=='S') x=j,y=e,z=1; } int flag=bfs(x,y,z); if(flag) cout<<"YES"<<endl; else cout<<"NO"<<endl; } }
标签:des style blog http io ar color os sp
原文地址:http://blog.csdn.net/u010372095/article/details/41865795