problem Descriptionwhen the poor princess was taken away again and again by the Knights, she was once again confronted with the ordeal of life. The devil has already sent a message that the princess will be eaten at T-time because he listens to rumors that eating the princess's flesh can also be immortal. The old king was so worried that he called on the world Warrior to save the princess. But the princess has long been accustomed to, she is convinced that Intelligent Knight LJ will certainly be able to rescue her.
now according to the spy, the princess was locked in a two-storey maze, the entrance to the maze is S (0,0,0), the location of the princess with P, space-time transmission machine with #, the wall with *, flat with. As soon as the Knights entered the space-time transmitter they would be transferred to the opposite position of the other, but if the position was to be transferred to the wall, the Knights would be killed. The Knights can only move around in the first layer, and each shift takes 1 moments. The movement of the layers can only pass through the time-space transfer machine and does not require any time.
Inputthe first line of input, C, represents a total of C test data, with three integer n,m,t on the previous line of each test data. N,m the size of the maze n*m (1 <= n,m <=10). T as you mean. The next n*m indicates the first layer of the maze arrangement, after the n*m to indicate the second floor of the maze layout situation.
OutputIf the Knights were able to find the princess at t time, output "YES" or Output "NO".
Sample Input15 5s*#*..#........****....#... *. P#.*..***.....*.*.#..
Sample OutputYES
This problem I first wrote the past, WA, looked at the discuss, only to find that there are a few pit points, these pits point I really did not think.
1. The ' # ' portal must be transmitted, there is no second option. 2. Both cases are dead ends when the portal is on either side, or when the portal is on one side and the wall is on the other. (Only the wall is considered)
1#include <cstdio>2#include <cstring>3#include <queue>4 using namespacestd;5 Const intmaxn= -;6 Charmaze[maxn][maxn][3];7 BOOLvis[maxn][maxn][3];8 intdx[4]={0,0,-1,1};9 intdy[4]={1,-1,0,0};Ten intn,m,t; One struct Point A { - intX,y,z,time; - }; the voidBFS () - { -memset (Vis,0,sizeof(Vis)); -Queue<point>que; + while(!que.empty ()) - Que.pop (); + Point SS; Ass.x=ss.y=1; atss.z=0; -Ss.time=0; - Que.push (ss); -vis[1][1][0]=true; - while(!que.empty ()) - { inPoint u=Que.front (); - Que.pop (); to //printf ("%d%d%d\n", u.x,u.y,u.z,u.time); + if(u.time>t) - Continue; the if(maze[u.x][u.y][u.z]==3) * { $printf"yes\n");Panax Notoginseng return ; - } the for(intI=0;i<4; i++) + { A Point du; thedu.x=u.x+Dx[i]; +du.y=u.y+Dy[i]; -du.z=u.z; $du.time=u.time+1; $ if(du.x<1|| du.x>n| | du.y<1|| Du.y>m) - Continue; - if(Vis[du.x][du.y][du.z]) the Continue; - if(!Maze[du.x][du.y][du.z])Wuyi Continue; the if(maze[du.x][du.y][du.z]==2) - { Wu if((maze[du.x][du.y][!du.z]) = =0|| vis[du.x][du.y][!Du.z] -|| maze[du.x][du.y][!du.z]==2) About Continue; $du.z=!du.z; - Que.push (du); -vis[du.x][du.y][du.z]=true; -vis[du.x][du.y][!du.z]=true; A } + Else the { - Que.push (du); $vis[du.x][du.y][du.z]=true; the } the } the } theprintf"no\n"); - } in intMain () the { the inttest; Aboutscanf"%d",&test); the while(test--) the { thescanf"%d%d%d",&n,&m,&t); + CharSTR[MAXN]; - for(intL=0;l<2; l++) the {Bayi for(intI=1; i<=n;i++) the { thescanf"%s",&str); - for(intj=1; j<=m;j++) - { the if(str[j-1]=='#') themaze[i][j][l]=2; the Else if(str[j-1]=='*') themaze[i][j][l]=0; - Else if(str[j-1]=='.'|| str[j-1]=='S') themaze[i][j][l]=1; the Else if(str[j-1]=='P') the {94maze[i][j][l]=3; the } the } the }98 } About BFS (); - }101 return 0;102}
My Code
HDU2102 a plan BFS simple problem have pit point good problem