点我看题目

题意 : 中文题不详述。

思路 :因为还牵扯到层的问题,所以用三维的解决,不过这个还是很简单的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)的更多相关文章

  1. hdu 1253 胜利大逃亡 (三维简单bfs+剪枝)

    胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  2. hdu 1253 胜利大逃亡(BFS)

    题目链接:点击链接 三维的BFS,刚开始一直超内存,超无语......  改了n多次终于AC了 #include <iostream> #include <stdio.h> # ...

  3. [ACM] hdu 1253 胜利大逃亡 (三维BFS)

    胜利大逃亡 Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这但是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,能够被表示 ...

  4. hdu 1253:胜利大逃亡(基础广搜BFS)

    胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  5. HDU 1253 胜利大逃亡 NYOJ 523【BFS】

    胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  6. hdu 1253 胜利大逃亡 (代码详解)解题报告

    胜利大逃亡 Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示 ...

  7. HDU 1253 胜利大逃亡 题解

    胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  8. hdu.1429.胜利大逃亡(续)(bfs + 0101011110)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  9. hdu 1429 胜利大逃亡(续)(bfs+位压缩)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

随机推荐

  1. 【itclx面向对象二】窥探itcl面向编程源码

    从上一篇博客看出,itcl的语法其实不难,但是有个缺点,编程习惯与当前类似C++常见的面向编程还是有些区别,并且在大型项目实施中这种方式很费劲. 于是有了itclx. 例如: 1.成员变量.成员方法调 ...

  2. mysql计算连续天数,mysql连续登录天数,连续天数统计

    mysql计算连续天数,mysql连续登录天数,连续天数统计 >>>>>>>>>>>>>>>>>& ...

  3. List集合即其遍历

    1. 首先List<E>集合继承与Collection<E>,是一个接口. ①  Collection (集合框架是JDK1.2版本出现的) ②   list:是有序的,元素可 ...

  4. ArryList vs LinkedList

    references: http://www.javaperformancetuning.com/articles/randomaccess.shtml http://stackoverflow.co ...

  5. 从V$SQL_PLAN中FORMAT执行计划

    10G版本 select sql_id from v$sqlarea where sql_text like'%xxx%'; select  * from v$sql_plan where sql_i ...

  6. artice与section的区别

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  7. 代理的使用 一(helloworld级别)

    个人理解(估计,半年一年后,在看到这篇文章的时候,会觉得,当时真的弱爆了) 当我们自定义view的时候,比如说view上面有几个按钮,那么我们在别的地方使用这个view的时候,怎么来处理这些点击事件呢 ...

  8. Java实战之03Spring-04Spring的数据库访问

    四.Spring的数据库访问 1.DAO模式 /** * 抽取的一个类 * @author zhy * */ public class JdbcDaoSupport { private QueryRu ...

  9. Visualsvn Server的搭建

    最近做项目在用svn,对svn有个初步了解,今天利用一点时间在本地配置了一个svn的服务端.整个过程分为以下几步: ①下载Visualsvn Server并且进行安装. ②安装好以后,在Visuals ...

  10. OpenJudge/Poj 1163 The Triangle

    1.链接地址: http://bailian.openjudge.cn/practice/1163 http://poj.org/problem?id=1163 2.题目: 总时间限制: 1000ms ...