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个方向. 第一维代表在 ...
随机推荐
- .Net WebAPI 增加Swagger
第一部分:创建项目 选择Web/ASP.NET Web Application 这里我选择的是WebAPI,并且增加MVC和Web API,权限部分选择无权限 第二部分:增加EF连接 因为项目需要连接 ...
- STL模板整理 Binary search(二分查找)
前言: 之前做题二分都是手动二分造轮子,用起来总是差强人意,后来看到STL才发现前辈们早就把轮子造好了,不得不说比自己手动实现好多了. 常用操作 1.头文件 #include <algorith ...
- vue-music 关于Search(搜索页面)-- 搜索历史
搜索历史展示每一次搜索过,并选中的关键字,保存数据到数组.搜索历史数据是需要在多个组件中共享的,所以保存在vuex 中 searchHistory 数组中,保存触发在搜索列表点击选中之后派发事件到se ...
- python request post上传文件额外注意点
通用用法 但上图的字段名,类型需要根据不同接口填写,如某服务接口: 因而对应的上传代码如下: # 输出参数:请求响应报文import requestsrequest_url = 'https://XX ...
- 转:VMware攻击界面分析
转:https://comsecuris.com/blog/posts/vmware_vgpu_shader_vulnerabilities/ Wandering through the Shady ...
- 洛谷P2713 罗马游戏
题目传送门 分析: 好吧,其实没什么好分析的,左偏树裸题. Code: #include<cstdio> #include<cstring> #include<cstdl ...
- EL使用技巧
☞控制页面元素显示与否 实现效果: 实现方案: ...... <div style="display:${empty param.hideTitle ? 'auto' : 'none' ...
- 爬楼梯(LintCode)
爬楼梯 假设你正在爬楼梯,需要n步你才能到达顶部.但每次你只能爬一步或者两步,你能有多少种不同的方法爬到楼顶部? 样例 比如n=3,中不同的方法 返回 3 用递归又超时了..于是又换了DP,dp并不熟 ...
- cobol COMP-3最后1位
"C" hex is positive, "D" hex is negative, and "F" hex is unsigned.
- 50 years, 50 colors HDU - 1498(最小点覆盖或者说最小顶点匹配)
On Octorber 21st, HDU 50-year-celebration, 50-color balloons floating around the campus, it's so nic ...