#include <iostream>
#include <cstdio>
using namespace std; const int MAX=; char maze[MAX][MAX][MAX]; struct {
int i,j,k;
}beg,des,que[],tmp,pushed;
int f,l;
char str[],n;
bool vis[MAX][MAX][MAX];
int dir[][]={,,,-,,,,,,,-,,,,,,,-}; bool ok(int i,int j,int k){
if(i<||i>=n||j<||j>=n||k<||k>=n||vis[i][j][k]||maze[i][j][k]=='X')
return false;
return true;
} bool bfs(){
int step=; int ti,tj,tk;
bool flag=false;
while(f<l){
int size=l-f;
step++;
while(size--){
tmp=que[f++];
if(tmp.i==des.i&&tmp.j==des.j&&tmp.k==des.k){
flag=true;
break;
}
for(int i=;i<;i++){
ti=tmp.i+dir[i][];
tj=tmp.j+dir[i][];
tk=tmp.k+dir[i][];
if(ok(ti,tj,tk)){
vis[ti][tj][tk]=true;
pushed.i=ti; pushed.j=tj; pushed.k=tk;
que[l++]=pushed;
}
}
}
if(flag) break;
}
if(flag){
printf("%d %d\n",n,step-);
return true;
}
return false;
} int main(){
while(scanf("%s %d",str,&n)!=EOF){
for(int i=;i<n;i++){
for(int j=;j<n;j++)
cin>>maze[i][j];
}
// cout<<"NO"<<endl;
scanf("%d%d%d",&beg.j,&beg.k,&beg.i);
scanf("%d%d%d",&des.j,&des.k,&des.i);
cin>>str;
// cout<<"YES"<<endl;
memset(vis,false,sizeof(vis));
f=l=;
if(beg.i==des.i&&beg.j==des.j&&beg.k==des.k){
printf("%d 0\n",n);
continue;
}
vis[beg.i][beg.j][beg.k]=true;
que[l++]=beg;
if(!bfs())
printf("NO ROUTE\n");
}
return ;
}

HDU 1240的更多相关文章

  1. hdu - 1240 Nightmare && hdu - 1253 胜利大逃亡(bfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1240 开始没仔细看题,看懂了发现就是一个裸的bfs,注意坐标是三维的,然后每次可以扩展出6个方向. 第一维代表在 ...

  2. hdu 1240:Asteroids!(三维BFS搜索)

    Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  3. HDU 1240 Asteroids! 解题报告

    //这道题做完我只有 三个感受  第一:坑: 第二 : 坑! 第三:还是坑! 咳咳  言归正传  WA了无数次之后才发现是输入进去时坐标时z, y, x的顺序输入的 题解   :  类似胜利大逃亡 只 ...

  4. HDU 1240 (简单三维广搜) Asteroids!

    给出一个三维的迷宫以及起点和终点,求能否到大终点,若果能输出最短步数 三维的问题无非就是变成了6个搜索方向 最后强调一下xyz的顺序,从输入数据来看,读入的顺序是map[z][x][y] 总之,这是很 ...

  5. hdu 1240 Asteroids! (三维bfs)

    Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  6. HDU 1240 Asteroids!

    三维广搜 #include <cstdio> #include <iostream> #include <cstring> #include <queue&g ...

  7. HDU 1240——Asteroids!(三维BFS)POJ 2225——Asteroids

    普通的三维广搜,须要注意的是输入:列,行,层 #include<iostream> #include<cstdio> #include<cstring> #incl ...

  8. hdu 1240 Asteroids!(BFS)

    题目链接:点击链接 简单BFS,和二维的做法相同(需注意坐标) 题目大意:三维的空间里,给出起点和终点,“O”表示能走,“X”表示不能走,计算最少的步数 #include <iostream&g ...

  9. HDU 1240 Asteroids!(BFS)

    题目链接 Problem Description You're in space.You want to get home.There are asteroids.You don't want to ...

  10. hdu 1240 3维迷宫 求起点到终点的步数 (BFS)

    题意,给出一个N,这是这个三空间的大小,然后给出所有面的状况O为空地,X为墙,再给出起始点的三维坐标和终点的坐标,输出到达的步数 比较坑 z是x,x是y,y是z,Sample InputSTART 1 ...

随机推荐

  1. Bayesian Regression

    Thus we see that there are very close similarities between this Bayesian viewpoint and the conventio ...

  2. 关于类和对象的进一步讨论之析构函数 C++

    析构函数也是一个特殊的成员函数.它的作用与构造函数相反.它的名字是在类名的前面加一个“~”符号.在C++中“~”是位取反运算符.当对象的生命结束时,会自动执行解析函数.以下几种情况会执行析构函数: 1 ...

  3. E20170828-mk

    utils  工具类; 效用; 实用工具; 实用菜单; Documentation  n. 记录; 证明某事属实的证据; 参考资料; 文献的编集,文件分类; receive   vt. 收到; 接待; ...

  4. Appium + python - online-install-apk

    import osfrom appium import webdriver# 安装app,为了方便,把app放到当前脚本同一目录os.system("adb install sina.apk ...

  5. 题解 UVA10587 【Mayor's posters】

    先讲一下:dalao @lisuier 发布的前一篇题解严格来讲是有错误的 比如下一组数据: 1 3 1 10 1 4 7 10 显然答案是3,然而用lisuier dalao的程序做出来的答案是2( ...

  6. TCP/IP详解(三)

    超时与重传: TCP在发送一个包时,启动一个定时器,如果在定时器溢出之前没有收到ACK,则认为发出的包丢失了,此时会重传丢失的包.这就是超时重传. 其中定时器的时间不是一个固定值,它是根据RTT计算的 ...

  7. BZOJ 2084 二分+hash OR Manacher

    思路: 二分+哈希 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...

  8. [Luogu 1850] noip16 换教室

    [Luogu 1850] noip16 换教室 好久没有更博客了,先唠嗑一会,花了两天的空闲时间大致做完了昨年的noip真题 虽然在经过思考大部分题目都可出解(天天爱跑步除外),但是并不知道考试时候造 ...

  9. Selenium获取input值的两种方法:WebElement.getAttribute("value")和WebElement.getText()

    在页面元素的定位中,有时候需要获取到元素的页面显示值,用来作为断言.例如,我需要获取email的值"amy1111@xxx.com". <input class=" ...

  10. Java code List Map, HashMap, JSON parser snippet

    package com.newegg.ec.solr.eventsalestoreservice.tuple; import kafka.message.MessageAndMetadata; pub ...