Sdut oj 1124 flying over the wilderness (3D BFS exercises)

Source: Internet
Author: User

Leap wilderness Time Limit: 5000 ms Memory limit: 65536 K any questions? Click Here ^_^ After the brave fario completed the task, he was quickly retreating to his own base. However, because there is a large group of follow-up troops behind it, fario should return to the base as soon as possible, or else he will be caught by the enemy.

Finally, fario came to the last stop: The field of telachel, where he can return to the base. However, the enemy persists. However, the geographical conditions of telazhir are very favorable for fario, and many lakes are everywhere. The enemy needs to bypass the road, but fario decided to find a way to return to the base as soon as possible.

Suppose that the field in telashir is a matrix of m * n, which has two kinds of terrain: P indicating flat, L indicating Lake, and fario can only stay on flat. The current position is in the upper left corner (), and the destination is in the lower right corner (m, n ). Fario can move or fly in the left and right directions. It takes 1 unit of time to move one cell. The flight time is mainly due to deformation, and the flight time consumption is very short. Therefore, no matter how far a flight is, only one unit of time is required. On the way to the flight, you cannot change directions, and a flight must eventually land on the ground. Of course, due to the limitation of energy, fario cannot fly without restrictions. The maximum distance he can fly is D. After knowing the above information, please help fario calculate the time it takes for him to arrive at the Base as quickly as possible. The first line of the input is a three integer, m (1 ≤ m ≤ 100), n (1 ≤ n ≤ 100), D (1 ≤ D ≤ 100 ). It indicates that the field is a matrix of m * n, and fario can only fly at most D distance. There are n characters in each line of the next m line, and there is no space between them. P indicates that the current position is flat, and L indicates the lake. Assume that () and (m, n) must be flat. Output an integer to indicate the shortest time required for fario to arrive at the base. If you cannot reach the base, output impossible. Sample Input
4 4 2PLLPPPLPPPPPPLLP
Sample output 5
Simple 3D BFS hand disability, WA several times, is not found t. d is written as f. d. I still have a wrong understanding of the meaning of the question. After a while, it may not be possible for a lake to fly, or the plain to fly.
# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
Const int n= 200; using namespace std; int mapp [N] [N]; bool vis [N] [N] [N]; int N, m, D; int mv [4] [2] = {}, {0,-1}, {}, {-}; struct node {int x, y, ans, d ;}; int st (int x, int y) {return x * y;} int BFS (int D) {node f, t; queue
      
        Q; memset (vis, 0, sizeof (vis); f. x = 0; f. y = 0; f. ans = 0; f. d = D; q. push (f); vis [f. x] [f. y] [f. d] = true; while (! Q. empty () {t = q. front (); if (t. x = n-1 & t. y = s-1) return t. ans; q. pop (); for (int I = 0; I <4; I ++) // walk {f. x = t. x + mv [I] [0]; f. y = t. y + mv [I] [1]; if (0 <= f. x & f. x
       
         = 1; num --) // find the current optimal route and try to fly as far as possible {f. x = t. x + st (mv [I] [0], num); f. y = t. y + st (mv [I] [1], num); // note that the plain land can fly, but the departure points and landing points must be plain if (0 <= f. x & f. x
        
         

5 5 4
PPPPP
PPPPP
LLLLL
LLLLL
LLLLL
Impossible
6 6 5
PPPPPL
PLPLPL
LLLLLL
PPPPPP
PPPPPP
PPPPPP
6
1 1 1
P
0
3 3 3
PPP
PPP
PPP
3
4 4 4
PLPL
LPLP
PPPP
LLLP
4
8 8 1
PPPPPPPP
PLPLPLPL
LLLLLLLL
PPPPPPPP
PPPPPPPP
PPPPPPPP
PPPPPPPP
PPPPPPPP
Impossible

Related Article

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.