Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求大神看看,为什么会超时#include<stdio.h> #include<string.h> #include<queue> using namespace std; char s[50][50][50]; int book[50][50][50]; struct node { int x, y, z; int step; }t, l; int main() { //freopen("in.txt", "r", stdin); int a, b, c; while (scanf("%d %d %d", &a, &b, &c) != EOF && (a != 0 || b != 0 || c != 0)) { scanf(" "); memset(book, 0, sizeof(book)); for (int i = 0; i < a; i++) { for (int j = 0; j <= b; j++) { gets(s[i][j]); for (int k = 0; k < c; k++) { if (s[i][j][k] == 'S') { t.x = i; t.y = j; t.z = k; t.step = 0; book[t.x][t.y][t.z] = 1; break; } } } } queue <node> que; /*while (!que.empty()) { que.pop(); }*/ que.push(t); int flag = 0; while (!que.empty()) { t = que.front(); que.pop(); if (s[t.x][t.y][t.z] == 'E') { flag = 1; printf("Escaped in %d minute(s).\n", t.step); break; } if (t.x-1 >= 0) { l = t; l.x--; l.step++; if (s[l.x][l.y][l.z] != '#' && book[l.x][l.y][l.z] == 0) { book[l.x][l.y][l.z] == 1; que.push(l); } } if (t.x+1 < a) { l = t; l.x++; l.step++; if (s[l.x][l.y][l.z] != '#' && book[l.x][l.y][l.z] == 0) { book[l.x][l.y][l.z] == 1; que.push(l); } } if (t.y-1 >= 0) { l = t; l.y--; l.step++; if (s[l.x][l.y][l.z] != '#' && book[l.x][l.y][l.z] == 0) { book[l.x][l.y][l.z] == 1; que.push(l); } } if (t.y+1 < b) { l = t; l.y++; l.step++; if (s[l.x][l.y][l.z] != '#' && book[l.x][l.y][l.z] == 0) { book[l.x][l.y][l.z] == 1; que.push(l); } } if (t.z-1 >= 0) { l = t; l.z--; l.step++; if (s[l.x][l.y][l.z] != '#' && book[l.x][l.y][l.z] == 0) { book[l.x][l.y][l.z] == 1; que.push(l); } } if (t.z+1 < c) { l = t; l.z++; l.step++; if (s[l.x][l.y][l.z] != '#' && book[l.x][l.y][l.z] == 0) { book[l.x][l.y][l.z] == 1; que.push(l); } } } if (!flag) { printf("Trapped!\n"); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator