Poj 2251 ultraviolet A 532

Source: Internet
Author: User

/*************************************** * ********************************** File Name: poj2251two. cpp Author: yubo Mail: yuzibode@126.com Created Time: May 30, 2014 Friday 05 hours 11 minutes 28 seconds learning focus: Three-dimensional maze, focus on the queue application, I learned a lot! Come on! 3 4 5S ..... ###.. ##.. ###. #############. ####... ###########. ####### E1 3 3 S ### E ### 0 0 0 ****************** **************************************** * *************/# include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
Using namespace std; int L, R, C; int S_x, S_y, S_z; char maze [40] [40] [40]; // mark map int dir [6] [3] = {-, 0,-, 0,-1 ,}; // array of 3D Orientation. Think about int vis [40] [40] [40]; typedef struct {int x, y, z; int depth; //} SE; int judge (int x, int y, int z) // self-written {if (x> = 0 & x
     
      
= 0 & y
      
        = 0 & z
       
         Q; SE q0, q1, q2; q0.x = I; q0.y = j; q0.z = k; q0.depth = 0; q. push (q0); while (! Q. empty () {q1 = q. front (); // read the first element to discard q in time. pop (); for (int I = 0; I <6; I ++) {int tmp1 = q1.x + dir [I] [0]; int tmp2 = q1.y + dir [I] [1]; int tmp3 = q1.z + dir [I] [2]; if (judge (tmp1, tmp2, tmp3 )&&! Vis [tmp1] [tmp2] [tmp3] & maze [tmp1] [tmp2] [tmp3]! = '#') {If (maze [tmp1] [tmp2] [tmp3] = 'E') {ans = q1.depth + 1; return;} q2.x = tmp1; q2.y = tmp2; q2.z = tmp3; q2.depth = q1.depth + 1; vis [tmp1] [tmp2] [tmp3] = 1; q. push (q2) ;}}} int main () {freopen ("in.txt", "r", stdin); char tmp; while (scanf ("% d", & L, & R, & C) {if (! L &&! R &&! C) break; memset (vis, 0, sizeof (vis); for (int I = 0; I
        
          > Maze [I] [j] [k]; if (maze [I] [j] [k] = 's') {S_x = I; S_y = j; s_z = k ;}}ans =-1; bfs (S_x, S_y, S_z); if (ans! =-1) // The trap printf ("Escaped in % d minute (s). \ n", ans); elseprintf ("Trapped! \ N ");}}
        
       
      
     
    
   
  
 

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.