标签:mit main cpp ons content das [1] strong 否则

1 3 3 4 20 0 1 1 1 0 0 1 1 0 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 0 0 0 0 0 1 1 0 0 1 1 0
11
| Run ID | Submit Time | Judge Status | Pro.ID | Exe.Time | Exe.Memory | Code Len. | Language | Author |
| 10887454 | 2014-06-18 09:50:19 | Time Limit Exceeded | 1253 | 2000MS | 944K | 1328 B | G++ | 长木 |
| 10887453 | 2014-06-18 09:49:37 | Accepted | 1253 | 1484MS | 996K | 1328 B | C++ | 长木 |
#include <cstdio>
#include <queue>
using std::queue;
int a, b, c, times;
int map[52][52][52];
bool vis[52][52][52];
const int mov[][3] = {
0, 0, 1, 0, 1, 0,
1, 0, 0, 0, 0, -1,
0, -1, 0, -1, 0, 0
};
struct Node{
int x, y, z, steps;
};
queue<Node> Q;
bool check(Node k){
if(k.x < 0 || k.y < 0 || k.z < 0 ||
k.x >= a || k.y >= b || k.z >= c) return 0;
if(vis[k.x][k.y][k.z] || map[k.x][k.y][k.z])
return 0;
return 1;
}
int BFS(){
while(!Q.empty()) Q.pop();
Node temp, now = {0};
vis[0][0][0] = 1;
if(a == b && a == c && a == 1) return 0;
Q.push(now);
while(!Q.empty()){
now = Q.front();
Q.pop();
if(now.steps == times) continue;
for(int i = 0; i < 6; ++i){
temp = now; ++temp.steps;
temp.x += mov[i][0];
temp.y += mov[i][1];
temp.z += mov[i][2];
if(check(temp)){
if(temp.x == a-1 && temp.y == b-1 && temp.z == c-1)
return temp.steps;
vis[temp.x][temp.y][temp.z] = 1;
Q.push(temp);
}
}
}
return -1;
}
int main(){
int t;
scanf("%d", &t);
while(t--){
scanf("%d%d%d%d", &a, &b, &c, ×);
for(int i = 0; i < a; ++i)
for(int j = 0; j < b; ++j)
for(int k = 0; k < c; ++k){
scanf("%d", &map[i][j][k]);
vis[i][j][k] = 0;
}
printf("%d\n", BFS());
}
return 0;
}标签:mit main cpp ons content das [1] strong 否则
原文地址:http://www.cnblogs.com/clnchanpin/p/6772428.html