标签:hdoj a计划
1 5 5 14 S*#*. .#... ..... ****. ...#. ..*.P #.*.. ***.. ...*. *.#..
YES#include<cstdio> #include<cstdlib> #include<cstring> #include<queue> using namespace std; char map[2][10][10]; int n,m,T; int mov[4][2]={0,1,0,-1,1,0,-1,0}; bool vis[2][10][10]; struct Node{ int x,y; int d,step; }v; int BFS(int px,int py,int f){ memset(vis,0,sizeof(vis)); int xx,yy; queue<Node>Q; v.x=px;v.y=py;v.d=f;v.step=0; Q.push(v);vis[f][px][py]=1; while(!Q.empty()){ Node u=Q.front();Q.pop(); f=u.d; for(int i=0;i<4;++i){ xx=u.x+mov[i][0]; yy=u.y+mov[i][1]; if(xx>=0&&xx<n&&yy>=0&&yy<m&&!vis[f][xx][yy]&&map[f][xx][yy]!='*'){ if(map[f][xx][yy]=='#'){ if(map[(f+1)%2][xx][yy]!='*'&&map[(f+1)%2][xx][yy]!='#'){ v.x=xx;v.y=yy; v.d=(f+1)%2; v.step=u.step+1; if(map[v.d][v.x][v.y]=='P'){ if(v.step<=T)return 1; else return 0; } vis[f][v.x][v.y]=1; vis[v.d][v.x][v.y]=1; Q.push(v); } else { vis[f][u.x][u.y]=1; vis[(f+1)%2][xx][yy]=1;} } else { v.x=xx;v.y=yy; v.d=u.d; v.step=u.step+1; if(map[v.d][v.x][v.y]=='P'){ if(v.step<=T)return 1; else return 0; } vis[v.d][v.x][v.y]=1; Q.push(v); } } } } return 0; } int main() { int i,j,t,s,e; scanf("%d",&t); while(t--){ scanf("%d%d%d",&n,&m,&T); int f; for(i=0;i<n;++i){ scanf("%s",map[0][i]); for(j=0;j<m;++j){ if(map[0][i][j]=='S'){s=i;e=j;f=0;} } } for(i=0;i<n;++i){ scanf("%s",map[1][i]); for(j=0;j<m;++j){ if(map[1][i][j]=='S'){s=i;e=j;f=1;} } } if(BFS(s,e,f))printf("YES\n"); else printf("NO\n"); } return 0; }
标签:hdoj a计划
原文地址:http://blog.csdn.net/r1986799047/article/details/44497525