Hdu 1728 Escape Maze (BFS)

Source: Internet
Author: User

Escape Maze Time limit:1000/1000ms (java/other) Memory limit:32768/32768k (Java/other) total submission (s): Accepted Su Bmission (s): 23font:times New Roman | Verdana | Georgiafont Size:←→problem Description Given a maze of MXN (M row, n column) with two positions in the Maze, Gloria wanted to move from one location to another in the maze, of course, some of the maze is open space, Gloria can cross , some places are obstacles, she must detour, from a location in the maze, can only walk to it adjacent to the 4 positions, of course, in the course of walking, Gloria can not go outside the maze. The headache is that Gloria is a person with no sense of direction, so she can not turn too many bends during the walk, otherwise she will faint. We assume that the given two positions are open space, initially, the direction of Gloria is undecided, she can choose any one of the 4 directions to start, and not to calculate a turn. Can Gloria go from one position to another? Input 1th acts as an integer T (1≤t≤100), representing the number of test data, followed by the T-Group test data, each set of test data,
The 1th act is two integers m, n (1≤m, n≤100), representing the number of rows and columns of the maze, followed by M-lines, each line containing n characters, where the character '. ' Indicates that the location is open space, the character ' * ' indicates that the position is a barrier, the input data is the only two characters, the last behavior of each group of test data 5 integers k, x1, y1, x2, y2 (1≤k≤10, 1≤x1, X2≤n, 1≤y1, Y2≤m), where K represents GL Oria the maximum number of bends that can be turned, (x1, y1), (x2, y2) represents two positions, where x1,x2 corresponds to a column, y1, and Y2 correspond to rows. Output each set of test data corresponds to a row, if the Gloria can go from one position to another position, outputs "yes", otherwise output "no". Sample Input
25 5...***.**...........* .... 1 1 1 1 35 5...***.**...........* .... 2 1 1) 1 3
Sample Output
Noyes
#include <iostream>#include<cstdio>#include<cstring>#include<queue>using namespacestd;intn,m,sx,sy,tx,ty,i,k,t;Charmp[ the][ the];intvis[ the][ the];intdr[4][2]={{1,0},{0,1},{-1,0},{0,-1} };structnode{intx,y,k;};intCheckintXinty) {    if(x>=0&& x<n && y>=0&& y<m)return 1; Else return 0;}intBFS () {node p; Queue<node>s; P.x=SX; P.Y=Sy; P.K=-1;   S.push (P); Vis[sx][sy]=1;  while(!S.empty ()) {Node Q=S.front ();       S.pop ();  for(intI=0;i<4; i++)       {           intxx=q.x+dr[i][0]; intyy=q.y+dr[i][1];  while(mp[xx][yy]!='*'&&Check (XX,YY)) {p.x=xx; P.Y=yy; P.K=q.k+1; if(!Vis[xx][yy])                   {S.push (P); VIS[XX][YY]=1; }               if(Xx==tx && yy==ty)if(p.k<=k)return 1; Else return 0; XX=xx+dr[i][0]; YY=yy+dr[i][1]; }       }   }   return 0;}intMain () {scanf ("%d",&t);  for(;t>0; t--) {scanf ("%d%d",&n,&m);  for(i=0; i<n;i++) scanf ("%s",&Mp[i]); scanf ("%d%d%d%d%d",&k,&sy,&sx,&ty,&tx); Sy--; sx--; ty--; tx--; memset (Vis,0,sizeof(VIS)); if(BFS ()) printf ("yes\n"); Elseprintf"no\n"); }    return 0;}

Hdu 1728 Escape Maze (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.