HDU 1253:胜利大逃亡(简单三维BFS)
pid=1253">胜利大逃亡
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24937 Accepted Submission(s): 9535
魔王住在一个城堡里,城堡是一个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
这题我TM逗比的犯那种逗比错误。。忘记打return 0;了 。。
。不知道是不是不小心删了。。。
代码事实上没什么好说的。。
简单的BFS。
。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath> using namespace std; const int maxn = 51;
const int INF = 0x3f3f3f3f;
int map[maxn][maxn][maxn];//地图
int vist[maxn][maxn][maxn];//标记数组
int a, b, c;//x,y,z
int mintime;//魔王回来的时间
int ans;
int dx[]= {1,-1,0,0,0,0};
int dy[]= {0,0,0,0,-1,1};
int dz[]= {0,0,-1,1,0,0};
int xx, yy, zz; struct point
{
int x, y, z;
int time;
};
queue<point>q; int bfs()
{
while( !q.empty() )
{
point temp = q.front();
q.pop();
if( temp.x == a-1 && temp.y == b-1 && temp.z == c-1 && temp.time<=mintime)
return temp.time;
for(int i=0; i<6; i++)
{
xx = temp.x + dx[i];
yy = temp.y + dy[i];
zz = temp.z + dz[i];
if( xx>=0 && xx<a && yy>=0 && yy<b && zz>=0 && zz<c && map[xx][yy][zz]!=1 && !vist[xx][yy][zz] )
{
point next;
next.x = xx;
next.y = yy;
next.z = zz;
next.time = temp.time + 1;
vist[xx][yy][zz] = 1;
q.push( next );
}
}
}
return -1;
} int main()
{
int cas;
scanf("%d", &cas);
while( cas-- )
{
while( !q.empty() ) q.pop();
memset(map, 0, sizeof(map));
memset(vist, 0, sizeof(vist));
scanf("%d%d%d%d", &a, &b, &c, &mintime);
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]);
if( map[a-1][b-1][c-1]==1 )
{
printf("-1\n");
continue;
}
if( a==1 && b==1 && c==1)
{
printf("0\n");
continue;
}
point start;
start.x = 0;
start.y = 0;
start.z = 0;
start.time = 0;
q.push( start );
vist[0][0][0] = 1;
ans = bfs();
printf("%d\n", ans);
}
return 0;
}
HDU 1253:胜利大逃亡(简单三维BFS)的更多相关文章
- [ACM] hdu 1253 胜利大逃亡 (三维BFS)
胜利大逃亡 Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这但是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,能够被表示 ...
- HDU 1253 胜利大逃亡(三维BFS)
点我看题目 题意 : 中文题不详述. 思路 :因为还牵扯到层的问题,所以用三维的解决,不过这个还是很简单的BFS,六个方向搜一下就可以了,一开始交的时候老是超时,怎么改都不对,后来看了一个人写的博客, ...
- hdu 1253 胜利大逃亡_三维
第一次做三维的题,这题跑g++超时了,c++过了. #include<iostream> #include<cstdio> #include<queue> usin ...
- hdu 1253 胜利大逃亡 (三维简单bfs+剪枝)
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- 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 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 ...
随机推荐
- iOS 9下支持的键盘类型:
http://blog.csdn.net/cloudox_/article/details/50532124
- Selenium WebDriver-操作键盘事件
# 注意: !!!操作操作系统的按键,需要先装pywin32,然后通过交互模式import win32api和import win32con判断是否安装成功,需要重启下cmd进入交互模式# 下载链接: ...
- PHP下mysql驱动概述
Overview of the MySQL PHP drivers 什么是API? 一 个应用程序接口(Application Programming Interface的缩写),定义了类,方法,函数 ...
- 简单使用jstl实现敏感字替换
package com.ceshi; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; ...
- 【bzoj1014】[JSOI2008]火星人prefix Splay+Hash+二分
题目描述 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 8 9 10 ...
- 安装环境 :win64
1.安装环境 :win64 1.1 下载mysql安装包地址: https://dev.mysql.com/downloads/file/?id=476233 2.安装 2.1 解压下载的ZIP压缩包 ...
- [luoguP2601] [ZJOI2009]对称的正方形(二维Hash + 二分 || Manacher)
传送门 很蒙蔽,不知道怎么搞. 网上看题解有说可以哈希+二分搞,也有的人说用Manacher搞,Manacher是什么鬼?以后再学. 对于这个题,可以从矩阵4个角hash一遍,然后枚举矩阵中的点,再二 ...
- Java面试题之谈谈reactor模型
reactor是什么? 事件驱动 可以处理一个或多个输入源 通过Service Handle同步的将输入事件采用多路复用分发给相应的Request Handler(一个或多个)处理 具体可参考:htt ...
- 欧拉函数之和(51nod 1239)
对正整数n,欧拉函数是小于或等于n的数中与n互质的数的数目.此函数以其首名研究者欧拉命名,它又称为Euler's totient function.φ函数.欧拉商数等.例如:φ(8) = 4(Phi( ...
- 线段树懒标记好题 HDU4578
(1)"1 x y c",代表 把区间 [x,y] 上的值全部加c (2)"2 x y c",代表 把区间 [x,y] 上的值全部乘以c (3)"3 ...