Created
April 6, 2017 05:06
-
-
Save Cycatz/0b33e706a79c8c482ee4e5ab42588951 to your computer and use it in GitHub Desktop.
[UVa]532 - Dungeon Master
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<iostream> | |
| #include<cstdio> | |
| #include<queue> | |
| using namespace std ; | |
| const int dx[6] = {0 , 0 , 0 , 0 , 1 , -1} ; | |
| const int dy[6] = {0 , 0 , 1 , -1 , 0 , 0} ; | |
| const int dz[6] = {1 , -1 , 0 , 0 , 0 , 0} ; | |
| const int maxn = 30 + 5 ; | |
| int l, r, c ; | |
| struct node{ | |
| int z , y , x , dist; | |
| node(int _z, int _y, int _x, int _d):z(_z),y(_y),x(_x),dist(_d){} | |
| }; | |
| int main(){ | |
| int bx , by , bz ; | |
| string gp[maxn][maxn] ; | |
| while((scanf("%d %d %d" , &l , &r , &c)) == 3 && (l + r + c)){ | |
| getchar(); | |
| for(int i = 0 ; i < l ; i++){ | |
| for(int j = 0 ; j < r ; j++){ | |
| getline(cin , gp[i][j]) ; | |
| for(int k = 0 ; k < c ; k++) | |
| if(gp[i][j][k] == 'S') bz = i , by = j , bx = k ; | |
| } | |
| getchar(); | |
| } | |
| //printf("%d %d %d\n" , bz , by , bx); | |
| int ans = 1e9 ; | |
| queue<node> q ; | |
| bool used[maxn][maxn][maxn] = {false} ; used[bz][by][bx] = true ; | |
| q.push(node(bz , by , bx , 0)); | |
| while(!q.empty()){ | |
| int cz = q.front().z , cy = q.front().y , cx = q.front().x , cd = q.front().dist ; q.pop() ; | |
| // printf("%d %d %d %d\n" , cz , cy , cx , cd); | |
| if(gp[cz][cy][cx] == 'E'){ans = cd ; break ;} | |
| for(int i = 0 ; i < 6 ; i++){ | |
| int z = cz + dz[i] , y = cy + dy[i] , x = cx + dx[i] ; | |
| if(z >= 0 && z < l && y >= 0 && y < r && x >= 0 && x < c && !used[z][y][x] && gp[z][y][x] != '#'){ | |
| used[z][y][x] = true ; | |
| q.push(node(z , y , x , cd + 1)) ; | |
| } | |
| } | |
| } | |
| if(ans == 1e9)puts("Trapped!"); | |
| else printf("Escaped in %d minute(s).\n" , ans); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment