题目链接: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)的更多相关文章

  1. hdoj 1429 胜利大逃亡(续) 【BFS+状态压缩】

    题目:pid=1429">hdoj 1429 胜利大逃亡(续) 同样题目: 题意:中文的,自己看 分析:题目是求最少的逃亡时间.确定用BFS 这个题目的难点在于有几个锁对于几把钥匙.唯 ...

  2. 胜利大逃亡(续)(bfs+状态压缩)

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

  3. HDU 1429 胜利大逃亡(续)(bfs+状态压缩,很经典)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)  ...

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

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

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

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

  6. HDU 1429 胜利大逃亡(续)(bfs)

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

  7. 九度1456胜利大逃亡【BFS】

    时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:4432 解决:1616 题目描述: Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会.魔王住在一个城堡 ...

  8. hdu1429 胜利大逃亡(续) 【BFS】+【状态压缩】

    题目链接:https://vjudge.net/contest/84620#problem/K 题目大意:一个人从起点走到终点,问他是否能够在规定的时间走到,在走向终点的路线上,可能会有一些障碍门,他 ...

  9. 胜利大逃亡--hdu --1253(bfs)

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

随机推荐

  1. 边框颜色为 tintColor 的 UIButton

    创建一个 UIButton 的子类,重写其方法: - (void)drawRect:(CGRect)rect { [[self layer] setCornerRadius:CORNER_RADIUS ...

  2. iOS:获取 NSDate 的年

    NSDate *currentDate = [NSDate date]; NSCalendar* calendar = [NSCalendar currentCalendar]; NSDateComp ...

  3. Logback中文文档(二):体系结构

    logback Logback 的基本结构充分通用,可应用于各种不同环境.目前,logback 分为三个模块:Core.Classic 和 Access. Core模块是其他两个模块的基础.Class ...

  4. 【WP8】自定义控件

    1.测量和安排布局:MeasureOverride, ArrangeOverride //测量(传入控件的可用大小) protected override Size MeasureOverride(S ...

  5. Array.prototype.removeBeginWithVal(删除数组内以某值开头的字符串对象)

    Array扩展方法: //author: Kenmu //created time: 2015-03-16 //function: 删除数组内以某值开头的字符串对象 Array.prototype.r ...

  6. web_submit_data详解

    定义:处理无状态或者上下文无关的表单提交.它用来生成表单的GET或POST请求,这些请求与Form自动生成的请求是一样的,发送这些请求时不需要表单上下文. 函数形式:web_submit_data( ...

  7. MSM--Memcached_Session_Manager介绍及使用

    MSM--Memcached_Session_Manager介绍及使用 http://www.iteye.com/topic/1125301 我们都知道对于一些大型的web2.0的网站,在正式部署时一 ...

  8. 【ML】人脸识别

    https://github.com/colipso/face_recognition https://medium.com/@ageitgey/machine-learning-is-fun-par ...

  9. Unity3D学习笔记——Android远程真机调试(Unity Remote)

    前言:当使用Unity开发移动端的游戏,特别是使用到手机的传感器,如重力感应等,调试的时候,很麻烦, 因为每次都需要编译成APK后安装到手机中测试,而Unity Remote便能很好的解决这个问题,U ...

  10. liunx(centos7 ) 免密码登录

    centos7 1.准备两台机器 如:(A机器) 和  (B机器) A机器 删除(.ssh目录下文件 known_hosts) 2. 对两台机器生成密钥 在  (A机器)上执行命令: [root@iZ ...