HUD2102 (base BFS)

Source: Internet
Author: User

Plan A

Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 16914 Accepted Submission (s): 4251


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 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.

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
#include <cstdio>#include<cstring>#include<queue>using namespacestd;Const intmaxn= the;structnode{intX,y,z,step; Node () {} node (intZintYintXintStep) {         This->x=x;  This->y=y;  This->z=Z;  This->step=step; }};intN,m,limit;Charmz[2][MAXN][MAXN];intvis[2][MAXN][MAXN];intdy[4]={0,1,0,-1};intdx[4]={1,0,-1,0};voidBFs () {memset (Vis,0,sizeof(VIS)); Queue<Node>que; Que.push (Node (0,0,0,0)); vis[0][0][0]=1;  while(!Que.empty ()) {Node now=Que.front (); Que.pop (); if(mz[now.z][now.y][now.x]=='P') {printf ("yes\n"); return ; }         for(intI=0;i<4; i++)        {            intny=dy[i]+now.y; intnx=dx[i]+now.x; intns=now.step+1; if(0<=ny&&ny<n&&0<=nx&&nx<m&&mz[now.z][ny][nx]!='*'&&!vis[now.z][ny][nx]&&ns<=limit) {Vis[now.z][ny][nx]=1; if(mz[now.z][ny][nx]=='#')                {                        intOpposite= (now.z==1?0:1); if(mz[opposite][ny][nx]!='*'&&mz[opposite][ny][nx]!='#')//prevent access to the two-storey relative position is time machine{Vis[opposite][ny][nx]=1; Que.push (Node (Opposite,ny,nx,now.step+1)); }                }                Else{Que.push (Node (Now.z,ny,nx,now.step+1)); } }}} printf ("no\n");}intMain () {intT; scanf ("%d",&T);  while(t--) {scanf ("%d%d%d",&n,&m,&limit);  for(intk=0;k<2; k++)        {             for(intI=0; i<n;i++) {scanf ("%*c");  for(intj=0; j<m;j++) {scanf ("%c",&Mz[k][i][j]); }} scanf ("%*c");    } BFS (); }    return 0;}

HUD2102 (base BFS)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.