Plan A
Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 13741 Accepted Submission (s): 3415
Problem description Poor princess in the devil after Time and again by the Knights rescued back, now, unfortunately, she once again face the test 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 enter the space, they will be transferred to the relative position of the other layer., but if the position is to be transferred to the wall, then the Knights will 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.
The first line of input, C, indicates 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.
Output "YES" If the Knights can find the princess at t time, otherwise the output "NO".
Sample Input15 5 14s*#*. #........****....#...*. p#.*. ***.....*.*.#..
Sample Outputyes
Sourcehdu 2007-6 Programming Contest This topic make me excited ah ... Written for a half day ... The result is test instructions understand wrong ... Mistakenly think to reach the transfer point, whether the transmission is optional ... However
as soon as the Knights enter the space, they will be transferred to the relative position of the other layer."It means that it will be transmitted as soon as it arrives at the transmission location ... Then if the transmission of the past is a stone, will die, that must not go to this conveyor, that is, this conveyor equivalent to obstacles. If the transmission past or the transfer machine, because the transmission is not selectable, it will enter the dead loop. Then this conveyor is also the equivalent of obstacles. The rest is nothing. Note that the exact time t is also can be rescued ... The example is exactly.
1 /*************************************************************************2 > File name:code/hdu/2102.cpp3 > Author:111qqz4 > Email: [Email protected]5 > Created time:2015 October 02 Friday 09:43 07 Seconds6 ************************************************************************/7 8#include <iostream>9#include <iomanip>Ten#include <cstdio> One#include <algorithm> A#include <cmath> -#include <cstring> -#include <string> the#include <map> -#include <Set> -#include <queue> -#include <vector> +#include <stack> -#include <cctype> + #defineY1 HUST111QQZ A #defineYn hez111qqz at #defineJ1 CUTE111QQZ - #defineMS (A,X) memset (A,x,sizeof (a)) - #defineLR DYING111QQZ - using namespacestd; - #definefor (i, n) for (int i=0;i<int (n); ++i) -typedefLong LongLL; intypedefDoubleDB; - Const intINF =0x3f3f3f3f; to Charmaze[2][ One][ One]; + intd[2][ One][ One]; - intdx[4] = {1,0,-1,0}; the intdy[4] = {0,-1,0,1}; * BOOLvis[2][ One][ One]; $ intn,m,t;Panax Notoginseng structnode - { the intx, y, z + intD; A BOOLOK () the { + if(x<0|| y<0|| x>=n| | Y>=M)return false; - if(Vis[z][x][y])return false; $ if(maze[z][x][y]=='*')return false; $ if(maze[z][x][y]=='#'&& (maze[z^1][x][y]=='#'|| maze[z^1][x][y]=='*'|| vis[z^1][x][y]))return false; - return true; - } the - };Wuyi node S; the BOOLBFS () - { WuS.x =0 ; -S.y =0; AboutS.z =0; $S.D =0 ; -Queue<node>Q; - Q.push (s); -vis[0][0][0] =true; A while(!q.empty ()) + { the node pre; -Pre =Q.front (); $ Q.pop (); the CharTMP =Maze[pre.z][pre.x][pre.y]; the //cout<<pre.z<< "" <<pre.x<< "" <<pre.y<<endl; the if(tmp=='P') the { - //cout<< "PRE.D" <<pre.d<<endl; in if(pre.d<=t)return true; the return false; the } About the the for(inti =0; I <4; i++) the { + node NXT; -Nxt.x = pre.x +Dx[i]; theNxt.y = Pre.y +Dy[i];BayiNxt.z =pre.z; theNXT.D = PRE.D +1; the if(!nxt.ok ())Continue; - if(maze[nxt.z][nxt.x][nxt.y]=='.'|| maze[nxt.z][nxt.x][nxt.y]=='P') - { the Q.push (NXT); thevis[nxt.z][nxt.x][nxt.y]=true; the } the Else - { theNxt.z = pre.z ^1; the Q.push (NXT); theVIS[NXT.Z][NXT.X][NXT.Y] =true;94 } the the } the }98 //cout<< "Ahhhh" <<endl; About return false; - 101 102 }103 intMain ()//You must teleport when you encounter a portal! Not a choice! 104{//So if a portal is routed to a location that is an obstacle, the transfer door will not be reachable directly! Equivalent to an obstacle! the #ifndef Online_judge106Freopen ("In.txt","R", stdin);107 #endif108 intT;109scanf"%d",&T); the while(t--)111 { theMS (VIS,false);113scanf" %d%d%d",&n,&m,&t); the for(inti =0; I < n; i++) scanf ("%s", maze[0][i]); the for(inti =0; I < n; i++) scanf ("%s", maze[1][i]); the if(BFS ())117 {118Puts"YES");119 } - Else121 {122Puts"NO");123 }124 } the 126 #ifndef Online_judge127 fclose (stdin); - #endif129 return 0; the}View Code
HDU 2102 a plan (BFS)