HDU 1253 胜利大逃亡 NYOJ 523【BFS】
胜利大逃亡
魔王住在一个城堡里,城堡是一个A*B*C的立方体,能够被表示成A个B*C的矩阵,刚開始Ignatius被关在(0,0,0)的位置,离开城堡的门在(A-1,B-1,C-1)的位置,如今知道魔王将在T分钟后回到城堡,Ignatius每分钟能从一个坐标走到相邻的六个坐标中的当中一个.如今给你城堡的地图,请你计算出Ignatius是否能在魔王回来前离开城堡(仅仅要走到出口就算离开城堡,假设走到出口的时候魔王刚好回来也算逃亡成功),假设能够请输出须要多少分钟才干离开,假设不能则输出-1.

特别注意:本题的測试数据很大,请使用scanf输入,我不能保证使用cin能不超时.在本OJ上请使用Visual C++提交.
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 | pid=1253">1253 |
2000MS | 944K | 1328 B | G++ | user=Changmu">长木 |
| 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;
}
HDU 1253 胜利大逃亡 NYOJ 523【BFS】的更多相关文章
- hdu 1253 胜利大逃亡 (三维简单bfs+剪枝)
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- [ACM] hdu 1253 胜利大逃亡 (三维BFS)
胜利大逃亡 Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这但是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,能够被表示 ...
- HDU 1253 胜利大逃亡(三维BFS)
点我看题目 题意 : 中文题不详述. 思路 :因为还牵扯到层的问题,所以用三维的解决,不过这个还是很简单的BFS,六个方向搜一下就可以了,一开始交的时候老是超时,怎么改都不对,后来看了一个人写的博客, ...
- hdu 1253:胜利大逃亡(基础广搜BFS)
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- HDU 1429 胜利大逃亡(续)(bfs+状态压缩,很经典)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) ...
- hdu 1253 胜利大逃亡 (代码详解)解题报告
胜利大逃亡 Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示 ...
- HDU 1253 胜利大逃亡 题解
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- HDU 1429 胜利大逃亡(续)(bfs)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- hdu - 1240 Nightmare && hdu - 1253 胜利大逃亡(bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1240 开始没仔细看题,看懂了发现就是一个裸的bfs,注意坐标是三维的,然后每次可以扩展出6个方向. 第一维代表在 ...
随机推荐
- ubuntu16.04安装最新版本的wine
1.安装源 sudo add-apt-repository ppa:wine/wine-builds sudo apt-get update 2.安装wine sudo apt-get install ...
- VS2013 打开项目时提示This project is incompatible with the current edition Visual Studio.
刚安装完成了Visual Studio 2013后,打开项目时,遇到以下问题 解决方法:在Visual Studio 2013 的菜单中打开“Tools",并打开“Extensions an ...
- 【ASP.NET】必须知道的ASP.NET核心处理
该找工作了,回头复习一下基础知识,增加一下理论知识的理解,下面我们看一下今天要说的. ASP.NET应用程序对象 一.请求的处理参数:上下文对象HttpContext 当一个请求到达ASP.NET服务 ...
- php 如何写 mysql insert into 语句
$sql="INSERT INTO moneytb (riqi,item,inout,cost,bz) VALUES ('$riqi','$item','$inout','$cost','$ ...
- Flask实战第52天:cms添加轮播图前端代码逻辑完成
首页我们在模态框中的保存按钮加一个id,这样方便我们选取这个按钮 <button type="button" class="btn btn-primary" ...
- HDU 6373 Pinball
Pinball Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
- AGC 012 D - Colorful Balls
题面在这里! 为什么atcoder都是神仙题啊qwq 首先发现如果要让 x,y 互换位置的话,要么通过他们直接换 (也就是x和y满足两种操作之一),要么间接换,通过一些其他的元素形如 x可以和 a[1 ...
- AGC 012 B - Splatter Painting
题面在这里! (显然首先想到反着做比较简单,每个点取第一次被覆盖到的颜色) 发现d非常小,那么是否可以暴力覆盖呢??? 考虑一个稠密图..暴力肯定就gg了啊... 不过我们可以对每一个点 i 记一个m ...
- 【动态规划+二分查找】POJ2533&POJ1631最长上升子序列(LIS)
POJ2533裸的LIS,时间复杂度为O(n^2) #include<iostream> #include<cstdio> using namespace std; +; in ...
- linux centos下安装docker
1.在vm中装好好centos后,更新内核 运行docker需要内核版本为3.8或者更高的版本,内核必须支持一种合适的存储驱动(Drivice Mapper.AUFS.vfs.btrfs.ZFS),默 ...