HDU 1253 胜利大逃亡 题解
胜利大逃亡
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 44540 Accepted Submission(s): 15483
魔王住在一个城堡里,城堡是一个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++提交.
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
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<fstream>
#include<iosfwd>
#include<sstream>
#include<fstream>
#include<cwchar>
#include<iomanip>
#include<ostream>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<ctime>
#include<algorithm>
#include<complex>
#include<cmath>
#include<valarray>
#include<bitset>
#include<iterator>
#define ll long long
using namespace std;
const double clf=1e-;
//const double e=2.718281828;
const double PI=3.141592653589793;
const int MMAX=;
//priority_queue<int>p;
//priority_queue<int,vector<int>,greater<int> >pq;]
int times,a,b,c,k;
struct node
{
int x,y,z,step;
};
int vis[][][];
int dir[][]={{,,},{,,-},{,-,},{,,},{,,},{-,,}};//六个自由度的矢量
int bfs(int x,int y,int z,int x1,int x2,int x3)
{
int i;
queue<node> q;
q.push(node{x,y,z,});
vis[x][y][z]=;
while(!q.empty())
{
node t=q.front();//读最开始的那个元素
q.pop();//取出来
if(t.step>times)
return -;//到不了返回-1
if(t.x==a-&&t.y==b-&&t.z==c-&&t.step<=times)
return t.step;//到了直接返回步数
for(i=;i<;i++)//6个维度
{
int dx=t.x+dir[i][];//x方向动
int dy=t.y+dir[i][];//y方向动
int dz=t.z+dir[i][];//z方向动
if(dx>=&&dy>=&&dz>=&&dx<=x1&&dy<=x2&&dz<=x3&&!vis[dx][dy][dz])
{
q.push(node{dx,dy,dz,t.step+});//搜索到的放进去
vis[dx][dy][dz]=;
}
}
}
return -;
}
int main()
{
scanf("%d",&k);
while(k--)
{
scanf("%d%d%d%d",&a,&b,&c,×);
for(int i=;i<a;i++)
{
for(int j=;j<b;j++)
{
for(int k=;k<c;k++)
{
scanf("%d",&vis[i][j][k]);
}
}
}
if(a==&&b==&&c==)
printf("0\n");
else
{
int ans=bfs(,,,a-,b-,c-);//0,0,0开始a-1,b-1,c-1结尾
printf("%d\n",ans);
}
}
return ;
}
Notes:模板题
2018-11-16 00:32:47 Author:LanceYu
HDU 1253 胜利大逃亡 题解的更多相关文章
- 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+剪枝)
胜利大逃亡 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 胜利大逃亡
Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A个B*C ...
- hdu - 1240 Nightmare && hdu - 1253 胜利大逃亡(bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1240 开始没仔细看题,看懂了发现就是一个裸的bfs,注意坐标是三维的,然后每次可以扩展出6个方向. 第一维代表在 ...
- HDU 1253 胜利大逃亡(BFS)
题目链接 Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会.魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A ...
- hdu 1253 胜利大逃亡(简单题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1253 题目大意:在所给的时间能顺利离开城堡. #include <iostream> #i ...
随机推荐
- Oracle EBS 11i下载的软件如何制作成linux使用的iso文件
1.cd \soft\ebs11i 2.unzip Bxxxxx.zip Disk1 3.mkisofs -o zj.iso -R -v Disk1 mkisofs -o zj.iso -R -v D ...
- [RN] windows7 安装 Realm Studio 后,打开报错 A JavaScript error occurred in the main process
windows7 安装 Realm Studio 后,打开报错 报错如下: A JavaScript error occurred in the main process Uncaught Exce ...
- vscode用服务打开html
①安装插件 此时右击会有: ②anywhere
- [LeetCode] 737. Sentence Similarity II 句子相似度之二
Given two sentences words1, words2 (each represented as an array of strings), and a list of similar ...
- dskms改为ckplayer播放器
将ckplayer代码文件夹上传到/var/www/html/public/static/plugins/目录下修改/var/www/html/application/home/view/defaul ...
- ros:init()
ros::init()是ROS程序调用的第一个函数,用于对ROS程序的初始化. ros::init()函数的声明在ROS代码中的./src/ros_comm/roscpp/include/ros/in ...
- [转帖]分布式事务之解决方案(XA和2PC)
分布式事务之解决方案(XA和2PC) https://zhuanlan.zhihu.com/p/93459200 3. 分布式事务解决方案之2PC(两阶段提交) 针对不同的分布式场景业界常见的解决方案 ...
- vue简介、入门、模板语法
在菜鸟教程上面学习的vue.js.同时结合vue中文文档网站,便于自己记录. vueAPI网站:API 1. 简介 Vue.js(读音 /vjuː/, 类似于 view) 是一套构建用户界面的渐进式框 ...
- javascript的对象与字符串相互转换
因为对象不利于网络传输,因此要转换成字符串,转换成字符串之后又要考虑怎么将这个字符串转换回对象,以便取得对象中的属性. 常用的做法是将对象转换为JSON字符串,这里的转换方法也是用的JSON官方提供的 ...
- centos7.x下环境搭建(五)—nginx搭建https服务
https证书获取 十大免费SSL证书 https://blog.csdn.net/ithomer/article/details/78075006 如果我们用的是阿里云或腾讯云,他们都提供了免费版的 ...