HDU 1253-大逃亡(裸-DBFS)
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
id=889" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="font-family:Verdana,Arial,sans-serif; border:1px solid rgb(211,211,211); background-color:rgb(227,228,248); color:rgb(85,85,85); display:inline-block; position:relative; padding:0px; margin-right:0.1em; zoom:1; overflow:visible; text-decoration:none">Practice
HDU1253
Description
魔王住在一个城堡里,城堡是一个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
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
Sample Output
11
<span style="font-size:18px;">#include <cstdio></span><span style="font-size: 17px;">
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
int A,B,C,T;
bool vis[60][60][60];
bool ma[60][60][60];
typedef struct node
{
int x,y,z,step;
};
int mv[6][3]={{0,0,1},{0,0,-1},{1,0,0},{-1,0,0},{0,1,0},{0,-1,0}};//6个方向
void bfs()
{
queue <node> Q;
node t; t.x=0;t.y=0;t.z=0;t.step=0;
vis[0][0][0]=1;
Q.push(t);
while(!Q.empty())
{
node f=Q.front();Q.pop();
if(f.x==A-1&&f.y==B-1&&f.z==C-1)
{
if(f.step<=T)
{
printf("%d\n",f.step);
return ;
}
else
{
puts("-1");
return ;
}
}
for(int i=0;i<6;i++)
{
t.x=f.x+mv[i][0];
t.y=f.y+mv[i][1];
t.z=f.z+mv[i][2];
if(0<=t.x&&t.x<A&&0<=t.y&&t.y<B&&0<=t.z&&t.z<C&&!vis[t.x][t.y][t.z]&&!ma[t.x][t.y][t.z])
{
vis[t.x][t.y][t.z]=1;
t.step=f.step+1;
Q.push(t);
}
}
}
puts("-1");
}
int main()
{
int K,i,j,k;
scanf("%d",&K);
while(K--)
{
scanf("%d%d%d%d",&A,&B,&C,&T);
memset(vis,0,sizeof(vis));
for(i=0;i<A;i++)
for(j=0;j<B;j++)
for(k=0;k<C;k++)
scanf("%d",&ma[i][j][k]);
bfs();
}
return 0;
}</span>
版权声明:本文博客原创文章,博客,未经同意,不得转载。
HDU 1253-大逃亡(裸-DBFS)的更多相关文章
- hdu 1253:胜利大逃亡(基础广搜BFS)
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- HDU 1253 胜利大逃亡 NYOJ 523【BFS】
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- HDU 1253:胜利大逃亡(简单三维BFS)
pid=1253">胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- 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 胜利大逃亡 (代码详解)解题报告
胜利大逃亡 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+状态压缩,很经典)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) ...
- hdu 1429 胜利大逃亡(续)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王 ...
随机推荐
- 在Java中使用MD5和BASE64
MD5: 在上一篇<Servlet的学习之Session(5)>中,为了能使获取的所有随机数都能有相同的位数,我们采用MD5获取随机数的消息摘要(或称数据指纹.数据摘要等等). MD5可以 ...
- 结构体的序列和还原(使用Move方法)
// 定义结构体 typeTmyRec= recordname:string[10];password:string[10];end; function RawToBytes(const AValue ...
- TMemoryStream、String与OleVariant互转
//////////////////////////////////////////////////////////////////////////////////功能: STRING 的内容流化到 ...
- nginx的sendfile指令的作用
linux为了解决对读文件产生的从应用空间到内核空间复制数据产生的效率影响引进了零拷贝.什么是零拷贝?这里就不多说了,请参考http://blog.csdn.net/crazyguang/articl ...
- 基于visual Studio2013解决面试题之0306打印第一次只出现一次的字符
题目
- 基于visual Studio2013解决面试题之0204最大子集数组
题目
- LeetCode——Count and Say
The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221 ...
- 14.4.8 Configuring the InnoDB Master Thread IO Rate 配置InnoDB Master Thread I/O Rate
14.4.8 Configuring the InnoDB Master Thread IO Rate 配置InnoDB Master Thread I/O Rate 主的master thread ...
- 随机IP代理
第一个例子就设置了一个代理IP,也是不靠谱的,最好的方式就是多设置几个,如第二个例子,通过http://www.youdaili.net/Daili/你可以找到很多代理IP, 抓取国内网站时尽量选取中 ...
- asp.net(C#)之NPOI"操作Excel
1.首先到网上下载"NPOI.DLL".引用. 2.新建一个操作类"ExcelHelper.cs": using System.Collections.Gene ...