Plan bfs hdu 2102

Source: Internet
Author: User

Plan bfs hdu 2102
Click Open Link

PlanTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 10939 Accepted Submission (s): 2667



Problem Description after the poor princess was captured by the Lord and rescued by the Knights again and again, unfortunately, she once again faces the test of her life. The devil has sent out a message saying that he will eat the princess at T moment, because he heard the rumor that the meat of the princess can survive forever. The elderly King was anxious to ask the warriors to save the princess. However, the princess has been used to it. She is confident that the brave knight LJ will be able to rescue her.
According to the investigation, the princess is locked in a two-layer maze. the entrance of the maze is S (, 0). The position of the princess is represented by P, and the space-time transmission is represented, the wall is represented by *, and flat is used.. As soon as the Knights enter the time-space transmitter, they will be transferred to the relative position of the other layer. However, if they are switched to the wall, the knights will be killed. In the first layer, the knights can only move between the left and right sides. Each movement takes 1 moment. Inter-layer movement can only pass through the time-space transmitter, and does not require any time.
The first line of Input C indicates a total of C test data. The first line of each test data has three integers, N, M, and T. N, M the size of the Maze N * M (1 <= N, M <= 10 ). T. The next N * M represents the layout of the first layer of the maze, and the next N * M represents the layout of the second layer of the maze.
Output if the knights can find the princess at T moment, they will Output "YES"; otherwise, "NO ".
Sample Input

15 5 14S*#*..#........****....#...*.P#.*..***.....*.*.#..

Sample Output
YES

SourceHDU 2007-6 Programming Contest Direct wide search, but there are several pitfalls:
1. The starting point is (0, 0, 0)
2. time less than or equal to t can all be
3. The first and second layers are both "#", so this point is the same as the second layer is.


//0MS1464K#include
 
  #include
  
   #include
   
    using namespace std;int n,m,t,sx,sy,ex,ey,sz,ez;int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};int vis[2][17][17];char g[2][17][17];struct sa{    int x,y,z,s;};int bfs(){    queue
    
     q;    memset(vis,0,sizeof(vis));    sa now,next;    now.z=0;now.x=0;now.y=0;now.s=0;    vis[sz][sx][sy]=1;    q.push(now);    while(!q.empty())    {        now=q.front();        q.pop();        if(now.z==ez&&now.x==ex&&now.y==ey)        {            if(now.s<=t)return 1;            return -1;        }        for(int i=0;i<4;i++)        {            int xx=now.x+dir[i][0];            int yy=now.y+dir[i][1];            int zz=now.z;            if(xx>=0&&xx
     
      =0&&yy
      
       

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.