HDU 1240 asteroids!

Source: Internet
Author: User

The road condition of each layer is given. 'O' indicates that this road can be taken. 'X' indicates that this road cannot be implemented. The program results require that the dimension of the square body be output (already given) and the minimum number of steps required for the start point to reach the end point.

Second group of data

 
Start 3XXX // bottom layer xxxxxxooo // middle layer ooooooooxxx // top layer xxxxxx0 0 12 2 1end



# Include <iostream> # include <cstdio> # include <queue> # include <cstring> using namespace STD; # define max 15 struct node {int x, y, z; int num; node (int x, int y, int Z, int num): x (x), y (Y), Z (z), num (Num) {} node () {}}; char N [Max] [Max] [Max]; node S, E; int V [Max] [Max] [Max], flag; int DX [] = {0, 0, 1,-, 0}; int dy [] = {0, 0, 0, 1,-1}; int DZ [] = {1, -, 0}; int main () {int n, x, y, z, I; char STR [10], C; while (CIN>> STR> N) {flag = 0; memset (v, 0, sizeof (v); For (Z = 1; Z <= N; Z ++) for (x = 1; x <= N; X ++) for (y = 1; y <= N; y ++) cin> N [x] [y] [Z]; CIN> S. x> S. y> S. z; CIN> E. x> E. y> E. z; CIN> STR; queue <node> q; V [S. X + 1] [S. Y + 1] [S. Z + 1] = 1; q. push (node (S. X + 1, S. Y + 1, S. Z + 1, 0); While (! Q. empty () {node TMP = Q. front (); q. pop (); If (TMP. X = E. X + 1 & TMP. y = E. Y + 1 & TMP. z = E. Z + 1) {flag = 1; cout <n <"" <TMP. num <Endl; break;} V [TMP. x] [TMP. y] [TMP. z] = 1; for (I = 0; I <6; I ++) {If (V [TMP. X + dx [I] [TMP. Y + dy [I] [TMP. Z + DZ [I] = 0 & N [TMP. X + dx [I] [TMP. Y + dy [I] [TMP. Z + DZ [I] = 'O') {q. push (node (TMP. X + dx [I], TMP. Y + dy [I], TMP. Z + DZ [I], TMP. num + 1) ;}}if (flag = 0) cout <"No route" <Endl;} 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.