bfs 胜利大逃亡
http://acm.hdu.edu.cn/showproblem.php?pid=1253
题目:
魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A个B*C的矩阵,刚开始Ignatius被关在(0,0,0)的位置,离开城堡的门在(A-1,B-1,C-1)的位置,现在知道魔王将在T分钟后回到城堡,Ignatius每分钟能从一个坐标走到相邻的六个坐标中的其中一个.现在给你城堡的地图,请你计算出Ignatius能否在魔王回来前离开城堡(只要走到出口就算离开城堡,如果走到出口的时候魔王刚好回来也算逃亡成功),如果可以请输出需要多少分钟才能离开,如果不能则输出-1.

Input
特别注意:本题的测试数据非常大,请使用scanf输入,我不能保证使用cin能不超时.在本OJ上请使用Visual C++提交.
Output
Sample Input
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
Sample Output
#include<iostream>
#include<queue>
#include<cstdio> using namespace std; int a,b,c,t;
int map[][][];
int dir[][]={,,,-,,,,,,,-,,,,,,,-}; struct node{
int x,y,z;
int step;
}; int bfs(){
node cur,next;
queue<node> q;
cur.x = ;
cur.y = ;
cur.z = ;
cur.step = ;
map[][][] = ;
q.push(cur);
while(!q.empty()){
cur = q.front();
q.pop();
if(cur.step<=t && cur.x==a && cur.y == b && cur.z == c)
return cur.step;
for(int i =;i<;i++){
int cc = cur.z + dir[i][];
int bb = cur.y + dir[i][];
int aa = cur.x + dir[i][];
if(aa> && aa<=a && bb> && bb<=b && cc> && cc<=c && !map[aa][bb][cc]){
map[aa][bb][cc] = ;
next.x = aa;
next.y = bb;
next.z = cc;
next.step = cur.step+;
q.push(next);
}
}
}
return -;
} int main(){
int k;
cin>>k;
while(k--){
cin>>a>>b>>c>>t;
for(int i=;i<=a;i++)
for(int j=;j<=b;j++)
for(int s=;s<=c;s++)
scanf("%d",&map[i][j][s]);
if(a+b+c>t){
cout<<"-1"<<endl;
continue;
}
cout<<bfs()<<endl;
}
return ;
}
bfs 胜利大逃亡的更多相关文章
- hdu.1429.胜利大逃亡(续)(bfs + 0101011110)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- hdu 1429 胜利大逃亡(续)(bfs+位压缩)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- HDU-1253 胜利大逃亡 (BFS)
此题可以做为三维深搜模板题.. 胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- HDOJ1253 胜利大逃亡 BFS
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...
- hdu 1253 胜利大逃亡 (三维简单bfs+剪枝)
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- 胜利大逃亡(续)(状态压缩bfs)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU1253 胜利大逃亡 BFS
胜利大逃亡 Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submiss ...
- 胜利大逃亡(续)(bfs+状态压缩)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- 胜利大逃亡(续)hdu1429(bfs)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
随机推荐
- CodeForces 628B New Skateboard
New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- AOD.net
ADO.NET中的五个主要对象 Connection 物件Connection 对象主要是开启程序和数据库之间的连结.没有利用连结对象将数据库打开,是无法从数据库中取得数据的.这个物件在ADO.NET ...
- [3D] 基本概念
[3D] 基本概念 环境光:对场景中所有的对象都提供了固定不变的照明.点光源:是从一个点发出的光.灯泡就可以理解为点光源.聚光源:正如它的的名字一样,是有方向和强弱的,电筒就是典型的聚光源. 方向光: ...
- HTTP和FTP的区别
原文地址: http://blog.csdn.net/xiaoxiangzhu660810/article/details/8291656 一.字面上来看 HTTP是Hyper Text Tr ...
- [转]SIP穿越NAT&FireWall解决方案
原文链接(也是转载)http://blog.csdn.net/yetyongjin/article/details/6881491.我修改了部分错字. SIP从私网到公网会遇到什么样的问题呢? 1 ...
- hdu 4217 Data Structure? 树状数组求第K小
Data Structure? Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- git学习笔记04-将本地仓库添加到GitHub远程仓库-git比svn先进的地方
第1步:创建SSH Key.在用户主目录下,看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsa和id_rsa.pub这两个文件,如果已经有了,可直接跳到下一步. 如果没有,打开Shel ...
- 使用Maven构件Web应用
一个典型的WAR文件会有如下目录结构: Maven的WEB项目结构: jetty-maven-plugin默认很好地支持了Maven的项目结构.在通常情况下,我们只需要直接在IDE中修改源码,IDE能 ...
- 08 高效的SQL
编写高效 SQL 需要以下知识 有关所查询内容的物理组织的知识 数据库能做什么的知识, 例如: 如果你不知道跳跃扫描索引及其用途, 那么你可能会看着模式说”索引丢了” SQL 所有错综复杂的知识 对目 ...
- js的事件处理程序
js事件处理程序一般有三种: 1.HTML事件处理程序 <body> <input type="button" value="点击" oncl ...