题目1456:胜利大逃亡(广度优先搜索BFS)
题目链接:http://ac.jobdu.com/problem.php?pid=1456
详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus
参考代码:
//
// 1456 胜利大逃亡.cpp
// Jobdu
//
// Created by PengFei_Zheng on 22/04/2017.
// Copyright © 2017 PengFei_Zheng. All rights reserved.
// #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cmath>
#include <queue>
#define MAX_SIZE 50
#define WALL 1
#define MOVE 6
using namespace std; int space[MAX_SIZE][MAX_SIZE][MAX_SIZE];
bool visit[MAX_SIZE][MAX_SIZE][MAX_SIZE]; struct N{
int x;
int y;
int z;
int t;
};
queue<N>myQueue; int change[][]={
,,,
-,,,
,,,
,-,,
,,,
,,-
}; int k, a, b, c, t; int BFS(int a, int b , int c){
while(!myQueue.empty()){
N nowP = myQueue.front();
myQueue.pop();
for(int i = ; i < MOVE ; i ++){
int nx = nowP.x + change[i][];
int ny = nowP.y + change[i][];
int nz = nowP.z + change[i][];
if(nx< || nx>=a || ny< || ny>=b || nz< || nz>=c) continue;
if(space[nx][ny][nz] == WALL) continue;
if(visit[nx][ny][nz] == true) continue;
N tmp;
tmp.x = nx;
tmp.y = ny;
tmp.z = nz;
tmp.t = nowP.t + ;
myQueue.push(tmp);
visit[nx][ny][nz] = true;
if(nx==a- && ny==b- && nz==c-) return tmp.t;
}
}
return -;
} int main(){
scanf("%d",&k);
while(k--){
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",&space[i][j][k]);
visit[i][j][k]=false;
}
}
}
while(!myQueue.empty()) myQueue.pop();
visit[][][] = true;
N tmp;
tmp.x=tmp.y=tmp.z=tmp.t=;
myQueue.push(tmp);
int cost = BFS(a,b,c);
if (cost <= t) printf("%d\n",cost);
else printf("-1\n");
}
return ;
} /**************************************************************
Problem: 1456
User: zpfbuaa
Language: C++
Result: Accepted
Time:20 ms
Memory:2132 kb
****************************************************************/
题目1456:胜利大逃亡(广度优先搜索BFS)的更多相关文章
- hdoj 1429 胜利大逃亡(续) 【BFS+状态压缩】
题目:pid=1429">hdoj 1429 胜利大逃亡(续) 同样题目: 题意:中文的,自己看 分析:题目是求最少的逃亡时间.确定用BFS 这个题目的难点在于有几个锁对于几把钥匙.唯 ...
- 胜利大逃亡(续)(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 胜利大逃亡 (三维简单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 1429 胜利大逃亡(续)(bfs)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- 九度1456胜利大逃亡【BFS】
时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:4432 解决:1616 题目描述: Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会.魔王住在一个城堡 ...
- hdu1429 胜利大逃亡(续) 【BFS】+【状态压缩】
题目链接:https://vjudge.net/contest/84620#problem/K 题目大意:一个人从起点走到终点,问他是否能够在规定的时间走到,在走向终点的路线上,可能会有一些障碍门,他 ...
- 胜利大逃亡--hdu --1253(bfs)
Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A个B*C ...
随机推荐
- c#包含类文件到csprj中
public ActionResult Index() { XDocument doc = XDocument.Load(@"G:\users\kim.gao\documents\visua ...
- What really happens when you navigate to a URL
As a software developer, you certainly have a high-level picture of how web apps work and what kinds ...
- 【玩转Golang】beego下实现martini中的透明式静态文件服务(static folder)效果。
出于效率等原因,最近将web框架由martini切换为了beego,其他地方都很平顺,只是两个框架的handler签名不一致,需要修改,所以耗时较长,这是预计到的.但是有一个地方没有预计到,也耗费了较 ...
- 【LSTM】Understanding-LSTMs
http://colah.github.io/posts/2015-08-Understanding-LSTMs/
- 前端可视化编程:liveReload安装,sublime 3
需要插件 sublime text3:View in Browser:LiveReload chrome:liveReload 配置方法 一:sublime text3 sublime 3下载地址: ...
- 使用editorconfig配置你的编辑器
摘要: 在团队开发中,统一的代码格式是必要的.但是不同开发人员使用的编辑工具可能不同,这样就造成代码的differ.今天给大家分享一个很好的方法来使不同的编辑器保持一样的风格. 不同的编辑器也有设置代 ...
- python 类属性 、实例属性,可变数据结构作为类属性需要注意的地方
1.一些经典的python错误不去阅读和不重视,就会把错误的做法带入到实际项目中来,甚至造成难以排查问题. 2.有一个大笨猪,按java写观察者模式,java写得是直接在类名下声明一个实例属性(不加s ...
- 线程同步 – lock和Monitor
在多线程代码中,多个线程可能会访问一些公共的资源(变量.方法逻辑等等),这些公共资源称为临界区(共享区):临界区的资源是不安全,所以需要通过线程同步对多个访问临界区的线程进行控制. 同样,有些时候我们 ...
- flexbox子盒子flex属性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Fiddler 抓取 Genymotion 数据包
对genymotion进行如下设置