Asteroids! HDU 1240 finally AC

Source: Internet
Author: User

/*
BFS is very watery. BFS won't be used at the beginning. It has been wrong many times with DFS. It should be due to a problem with the algorithm. I think this topic uses DFS.
Yes.
*/
# Include <iostream> // 2389356 2010-04-27 11:23:31 accepted 1240 0 Ms 308 K 1495 B C ++ regret
# Include <queue>
# Include <cstring>
# Include <cmath>
Using namespace STD;

Char map [12] [12] [12];
Bool hash [12] [12] [12];
Bool flag;
Int dir [6] [3] = {0, 0, 1}, {0, 1, 0}, {0, 0,-1}, {0, -1, 0}, {1, 0, 0}, {-1, 0, 0 }};
Int A, B, C;
Int D, E, F;
Int T;
Int N;
Struct Node
{
Int X;
Int y;
Int Z;
Int num;
};
Queue <node> q;

Int BFS (INT Si, int SJ, int SK)
{
Node N, P;
N. x = SI;
N. Y = SJ;
N. z = Sk;
N. num = 0;
Int I;
Q. Push (N );
Hash [Si] [SJ] [SK] = false;
While (! Q. Empty ())
{
N = Q. Front ();
If (N. x = F & N. Y = E & N. z = D & N. num = T)
{
Flag = true;
Cout <n <"" <n. Num <Endl;
Break;
}
If (N. Num> T)
{
Break;
}
Q. Pop ();
For (I = 0; I <6; I ++)
{
P. x = n. x + dir [I] [0];
P. Y = n. Y + dir [I] [1];
P. z = n. Z + dir [I] [2];

If (P. x> = 0 & P. x <n & P. y> = 0 & P. Y <n & P. z> = 0 & P. z <n & hash [p. x] [p. y] [p. z] & map [p. x] [p. y] [p. z] = 'O ')
{
P. num = n. Num + 1;
Q. Push (P );
Hash [p. x] [P. Y] [P. Z] = false;
}
}

}
Return 1;

}
Int main ()
{
Char STR [12];
Int I, J, K;
While (CIN> STR> N)
{
For (I = 0; I <n; I ++)
For (j = 0; j <n; j ++)
For (k = 0; k <n; k ++)
Cin> map [I] [J] [k];
Cin> A> B> C;
Cin> D> E> F;
Cin> STR;
T = (INT) (FABS (1.0 * a-d) + FABS (1.0 * B-e) + FABS (1.0 * C-f )); // This ce passed during the provincial Competition
Flag = false;
Memset (hash, true, sizeof (hash); // At the beginning, an error is marked here. It should be specified later. Otherwise, an error occurs when writing data.
BFS (C, B, );
If (! Flag)
Cout <"No route" <Endl;
}

}

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.