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 ...
随机推荐
- maven warnning 'build.plugins.plugin.version' is missing
裝完maven后,package或clean时出错:[WARN] [WARN] Some problems were encountered while building the effective ...
- 解决js 0.1 + 0.2 = 0.30000000000000004 的位数精度问题
https://www.html.cn/archives/7340 解决办法 parseFloat((0.1 + 0.2).toFixed(10))
- JS通过指定大小来压缩图片
安装: npm i image-conversion --save 引入: <script src="https://cdn.jsdelivr.net/gh/WangYuLue/ima ...
- [LeetCode] 30. Substring with Concatenation of All Words 串联所有单词的子串
You are given a string, s, and a list of words, words, that are all of the same length. Find all sta ...
- Linux网络编程综合运用之MiniFtp实现(一)
春节过后,万物复苏,在这元宵佳节的前一天,决定继续开启新年的学习计划,生命在于运动,提高源于学习,在经过漫长的Linux网络编程学习后,接下来会以一个综合的小项目来将所学的知识点综合运用,首先是对项目 ...
- AtCoder Grand Contest 039 简要题解
从这里开始 比赛目录 Problem A Connection and Disconnection 简单讨论即可. Code #include <bits/stdc++.h> using ...
- Python 爬取 13 个旅游城市,告诉你五一大家最爱去哪玩?
五一假期已经结束,小伙伴是不是都还没有玩过瘾?但是没办法,还有很多bug等着我们去写,同样还有需要money需要我们去赚.为了生活总的拼搏. 今年五一放了四天假,很多人不再只是选择周边游,因为时间充裕 ...
- iptables如何安全的清空规则
使用 /sbin/iptables -F 要小心,搞不好,你就马上同服务器断开连接了 如果想清空的话,先执行 /sbin/iptables -P INPUT ACCEPT 然后执行 /sbin/ipt ...
- [转帖]银河麒麟Kydroid 2.0全新发布:原生支持海量安卓APP
银河麒麟Kydroid 2.0全新发布:原生支持海量安卓APP https://news.cnblogs.com/n/652299/将手机操作系统 转移到 桌面 跟chromebook 类似的策略吧 ...
- 【UOJ#32】【UR #2】跳蚤公路(最短路)
[UOJ#32][UR #2]跳蚤公路(最短路) 题面 UOJ 题解 不难发现要求的就是是否存在负环.也就是我们只需要找到所有的负的简单环,很容易就可以想到维护路径上和\(x\)相关的内容,即维护一下 ...