Hdu 1180 weird stairway

Source: Internet
Author: User

Hdu 1180 weird stairway
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission (s): 8611 Accepted Submission (s): 2118

After the official start of Problem DescriptionHogwarts, Harry found that some stairs in Hogwarts were not static. On the contrary, they changed their directions every minute.
For example, in the following example, the first stair is in the vertical direction. One minute later it moves to the horizontal direction, and another minute it returns to the vertical direction. harry found it hard for him to find the path that would allow him to reach his destination as quickly as possible. At this time, Ron (Harry's best friend) told Harry that he had a magic item to help him find the path, the magic spell on that magic item is exactly written by you.

There are multiple groups of Input test data. Each group is described as follows:
The first row has two numbers, M and N. Next is a map of N columns in the M row. '*' indicates an obstacle ,'. 'indicates a corridor,' | 'or'-'indicates a stair and its position at the beginning:' | 'indicates that the stair is in the vertical direction at the beginning, '-' indicates that the stair is in the horizontal direction at the beginning. there is also a 's' in the map that is the starting point, 't' is the target, 0 <= M, N <= 20, there will be no two connected ladders in the map. harry can only stay '. 'or' S 'and' T.

Output has only one row, containing a number T, indicating the shortest time to reach the target.
Note: Harry can only walk to the adjacent grid each time, but cannot walk diagonally. Each movement happens to be a minute, and it takes only one minute for Harry to climb the stairs and pass the stairs to the opposite side, harry never stays on the stairs. and every time the stairs were moved, Harry changed his direction.

Sample Input

5 5**..T**.*...|...*.*.S....

Sample Output
7HintThe Hint map is as follows:

# Include
 
  
# Include
  
   
# Include
   
    
Using namespace std; char map [25] [25]; int vis [25] [25]; int dir [4] [2] =, 0,-1}; int n, m; int startx, starty; struct node {int x, y; int time;} p, v, next; int chek (int, int B, int c, int d, int step) // the current position of the stair (a, B), the position (c, d) after the stair ), the time used before the stair (step ). {if (c> = 0 & c
    
     
= 0 & d
     
      
Q; memset (vis, 0, sizeof (vis); p. x = startx; p. y = starty; p. time = 0; vis [p. x] [p. y] = 1; q. push (p); while (! Q. empty () {v = q. front (); q. pop (); for (I = 0; I <4; I ++) {next. x = v. x + dir [I] [0]; next. y = v. y + dir [I] [1]; if (next. x> = 0 & next. x
      
        = 0 & next. y
       
         = 0 & p. x
        
          = 0 & p. y
         
           > N> m) {for (I = 0; I
          
            > Map [I] [j]; if (map [I] [j] = 's') {startx = I; starty = j ;}} printf ("% d \ n", bfs (startx, starty);} return 0 ;}
          
         
        
       
      
     
    
   
  
 


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.