hdu-1240 Nightmare && hdu-1253 Victory Grand Escape (BFS)

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=1240

began not to carefully read the question, understand the discovery is a bare bfs, pay attention to the coordinates are three-dimensional, and then each can expand out of 6 directions.

The first dimension is represented on the third level. The latter two dimensions represent rows and columns.

1#include <cstdio>2#include <cstring>3#include <queue>4 using namespacestd;5 struct Point6 {7     intX,y,z,step;8     BOOL operator< (ConstPoint a)Const9     {Ten         returnStep>A.step; One     } A }; - Point t,e; - intN; the Charmaze[ the][ the][ the]; - intused[ the][ the][ the]; - intdir[6][3]={{-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,0,-1},{0,0,1}}; -  + voidBFS () - { +memset (Used,0,sizeof(used)); APriority_queue<point>que; at Que.push (t); -used[t.z][t.x][t.y]=1; -      while(!que.empty ()) -     { -Point s=que.top (); Que.pop (); -       //printf ("%d%d%d%d\n", s.z,s.x,s.y,s.step); in         if(S.X==E.X&AMP;&AMP;S.Y==E.Y&AMP;&AMP;S.Z==E.Z) {printf ("%d%d\n", N,s.step);return;} -          for(intI=0;i<6; i++) to         { +t.x=s.x+dir[i][0],t.y=s.y+dir[i][1],t.z=s.z+dir[i][2]; -             if(t.x>=0&&t.x<n&&t.y>=0&&t.y<n&&t.z>=0&&t.z<n&&maze[t.z][t.x][t.y]!='X'&&!Used[t.z][t.x][t.y]) the             { *t.step=s.step+1; $used[t.z][t.x][t.y]=1;Panax Notoginseng Que.push (t); -             } the         } +     } Aprintf"NO route\n"); the } + intMain () - { $    //freopen ("A.txt", "R", stdin); $     Chars[Ten]; -      while(~SCANF ("%s", s)) -     { thescanf"%d",&n); -          for(intI=0; i<n;i++)Wuyi              for(intj=0; j<n;j++) thescanf"%s", Maze[i][j]); -scanf"%d%d%d",&t.y,&t.x,&t.z); Wut.step=0; -scanf"%d%d%d",&e.y,&e.x,&e.z); Aboutscanf"%s", s); $ BFS (); -     } -     return 0; -}

hdu-1240 Nightmare && hdu-1253 Victory Grand Escape (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.