HDU 1253 胜利大逃亡(三维BFS)
题意 : 中文题不详述。
思路 :因为还牵扯到层的问题,所以用三维的解决,不过这个还是很简单的BFS,六个方向搜一下就可以了,一开始交的时候老是超时,怎么改都不对,后来看了一个人写的博客,他说用C++交300ms,G++交600ms,我就改成C++交了,果然AC了,不过。。。。用了900ms。。。。。我也懒得改了,也不知道为什么G++交超时
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <queue> using namespace std ; int mapp[][][] ;
bool vis[][][] ;
int dir[][] = {{,,},{-,,},{,,},{,-,},{,,},{,,-}} ;
int A, B, C,T ;
int sum ;
struct node
{
int x ;
int y ;
int z ;
int timee ;
} temp,temp1 ; void BFS()
{
queue<node>que ;
memset(vis,false,sizeof(vis)) ;
vis[][][] = true ;
temp.x = ,temp.y = ,temp.z = ;
temp.timee = ;
que.push(temp) ;
while(!que.empty())
{
node temp1 = que.front() ;
que.pop() ;
if(temp1.x == A- && temp1.y == B- && temp1.z == C-)
{
sum = temp1.timee;
return ;
}
for(int i = ; i < ; i++)
{
int xx = temp1.x+dir[i][] ;
int yy = temp1.y+dir[i][] ;
int zz = temp1.z+dir[i][] ;
if(!vis[xx][yy][zz] && mapp[xx][yy][zz] == && xx >= && xx < A && yy >= && yy < B && zz >= && zz < C)
{
temp.x = xx ;
temp.y = yy ;
temp.z = zz ;
temp.timee=temp1.timee+;
vis[xx][yy][zz] = true ;
que.push(temp) ;
}
}
}
}
int main()
{
int K ;
scanf("%d",&K) ;
while(K--)
{
sum = ;
memset(mapp,,sizeof(mapp)) ;
scanf("%d %d %d %d",&A,&B,&C,&T );
for(int i = ; i < A ; i++)
for(int j = ; j < B ; j++)
for(int k = ; k < C ; k++)
scanf("%d",&mapp[i][j][k]) ;
BFS();
if(sum > T)
printf("-1\n") ;
else printf("%d\n",sum) ;
}
return ;
}
HDU 1253 胜利大逃亡(三维BFS)的更多相关文章
- hdu 1253 胜利大逃亡 (三维简单bfs+剪枝)
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- hdu 1253 胜利大逃亡(BFS)
题目链接:点击链接 三维的BFS,刚开始一直超内存,超无语...... 改了n多次终于AC了 #include <iostream> #include <stdio.h> # ...
- [ACM] hdu 1253 胜利大逃亡 (三维BFS)
胜利大逃亡 Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这但是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,能够被表示 ...
- 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 胜利大逃亡 (代码详解)解题报告
胜利大逃亡 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 + 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 ...
随机推荐
- [转]深入理解jQuery插件开发
如果你看到这篇文章,我确信你毫无疑问会认为jQuery是一个使用简便的库.jQuery可能使用起来很简单,但是它仍然有一些奇怪的地方,对它基本功能和概念不熟悉的人可能会难以掌握.但是不用担心,我下面已 ...
- 利用CodeSmith生成抽象工厂步骤
其实CodeSmith挺好的,帮我们主动生成不少代码,并且代码质量不错,下面就来介绍一下利用CodeSmith生成抽象工厂步骤 打开codesmith模板的buildall 注意path的设置,因为后 ...
- SQLServer 2008数据库查看死锁、堵塞的SQL语句
--每秒死锁数量 SELECT * FROM sys.dm_os_performance_counters WHERE counter_name LIKE 'Number of Deadlocks ...
- 电脑中java环境的搭建
- C# ACM poj1007
求逆序数,快排 public static void acm1007(int a, string[] c) { Dictionary<int, string> dic = new Dict ...
- FlashBuilder启动时一闪而过
晚上的时候把项目目录直接剪切走了 早晨就打不开了 去workspace看log .\workspace\.metadata\.log 发现如下代码!MESSAGE Could not read me ...
- AngularJS的学习网站及相关资源整理
学习angularjs的网站及相关资源的整理,会不断更新. angularJs的官网:https://angularjs.org/ API文档:https://docs.angularjs ...
- OpenJudge / Poj 2141 Message Decowding
1.链接地址: http://poj.org/problem?id=2141 http://bailian.openjudge.cn/practice/2141/ 2.题目: Message Deco ...
- Boot Petalinux Project Using a remote system
通过jtag实现在远程服务器端下载petalinux image到连接在本地PC的开发板上的方法. 具体连接方式为 比如Host的系统为Windows,Remote system为运载在远程服务器上的 ...
- 简单模拟Hibernate的主要功能实现
在学习期间接触到Hibernate框架,这是一款非常优秀的O/R映射框架,大大简化了在开发web项目过程中对数据库的操作.这里就简单模拟其底层的实现. /*******代码部分,及其主要注解***** ...