HDU 1180 weird stairway

Source: Internet
Author: User

HDU 1180 weird stairway
A strange stairwayTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission (s): 10044 Accepted Submission (s): 2490



After the official start of Problem Description Hogwarts, Harry found that some stairs in Hogwarts were not static. On the contrary, they changed 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
7HintHint The map is as follows:

Source Gardon-DYGG Contest 1
Recommend JGShining | We have carefully selected several similar problems for you: 1175 1240 1254 1044


It's really weird .. ..
# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Include
        # Include
         
           Using namespace std; int n, m, x2, y2; char mat [25] [25]; // int vis [25] [25]; int dir [4] [2] = {0, 1}, {0,-1}, {}, {-}; int pre [25] [25]; struct node {int x, y; int step; bool friend operator <(node pp, node o) {return pp. step> o. step ;}}; bool check (node a) {if (. x <0 |. y <0 |. x> = n |. y> = m | mat [. x] [. y] = '*' | pre [. x] [. y] & pre [. x] [. y] <=. step) // click the point you have walked. Therefore, you do not need to mark the vis array, but use the number of steps to mark it, provided that return 0; return 1;} is less than the number of steps in the previous step ;} int bfs (int x, int y) {int I, p, l; priority_queue
          
            Q; node st, ed; st. x = x; st. y = y; st. step = 0; q. push (st); while (! Q. empty () {st = q. top (); q. pop (); if (st. x = x2 & st. y = y2 & mat [st. x] [st. y] = 'T') return st. step; for (I = 0; I <4; I ++) {ed. x = st. x + dir [I] [0]; ed. y = st. y + dir [I] [1]; ed. step = st. step + 1; if (mat [ed. x] [ed. y] = '|') {if (ed. x = st. x & (st. step) & 1 = 0) // steps left and right, and the ladder is "|"; goes up the stairs ed. step + = 1; if (ed. y = st. y & (st. step) & 1 = 1) // go up and down, and the ladder is "-". Go elsewhere. Ed. step + = 1; ed. x + = dir [I] [0]; ed. y + = dir [I] [1];} else if (mat [ed. x] [ed. y] = '-') {if (ed. x = st. x & (st. step) & 1 = 1) // walk left and right, and the ladder is "|";, go to other places. Ed. step + = 1; if (ed. y = st. y & (st. step) & 1 = 0) // go up and down, and the ladder is "-" Up the stairs ed. step + = 1; ed. x + = dir [I] [0]; ed. y + = dir [I] [1];}/* if (mat [ed. x + 1] [ed. y] = '|') ed. x = ed. x + 2; else if (mat [ed. x-1] [ed. y] = '|') ed. x = ed. x-2; else if (mat [ed. x] [ed. y + 1] = '-') ed. y = ed. y + 2; else if (mat [ed. x] [ed. y-1] = '-') ed. y = ed. y-2; */if (! Check (ed) continue; pre [ed. x] [ed. y] = ed. step; // vis [ed. x] [ed. y] = 1;/* for (p = 0; p
           
          
         
       
      
     
    
   
  
 

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.