G - Asteroids!

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d
& %I64u

Description

You're in space. 

You want to get home. 

There are asteroids. 

You don't want to hit them. 
 

Input

Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. 



A single data set has 5 components: 



Start line - A single line, "START N", where 1 <= N <= 10. 



Slice list - A series of N slices. Each slice is an N x N matrix representing a horizontal slice through the asteroid field. Each position in the matrix will be one of two values: 



'O' - (the letter "oh") Empty space 



'X' - (upper-case) Asteroid present 



Starting Position - A single line, "A B C", denoting the <A,B,C> coordinates of your craft's starting position. The coordinate values will be integers separated by individual spaces. 



Target Position - A single line, "D E F", denoting the <D,E,F> coordinates of your target's position. The coordinate values will be integers separated by individual spaces. 



End line - A single line, "END" 



The origin of the coordinate system is <0,0,0>. Therefore, each component of each coordinate vector will be an integer between 0 and N-1, inclusive. 



The first coordinate in a set indicates the column. Left column = 0. 



The second coordinate in a set indicates the row. Top row = 0. 



The third coordinate in a set indicates the slice. First slice = 0. 



Both the Starting Position and the Target Position will be in empty space. 


 

Output

For each data set, there will be exactly one output set, and there will be no blank lines separating output sets. 



A single output set consists of a single line. If a route exists, the line will be in the format "X Y", where X is the same as N from the corresponding input data set and Y is the least number of moves necessary to get your ship from the starting position to
the target position. If there is no route from the starting position to the target position, the line will be "NO ROUTE" instead. 



A move can only be in one of the six basic directions: up, down, left, right, forward, back. Phrased more precisely, a move will either increment or decrement a single component of your current position vector by 1. 


 

Sample Input

START 1
O
0 0 0
0 0 0
END
START 3
XXX
XXX
XXX
OOO
OOO
OOO
XXX
XXX
XXX
0 0 1
2 2 1
END
START 5
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
0 0 0
4 4 4
END
 

Sample Output

1 0
3 4
NO ROUTE
 
/*
Author: 2486
Memory: 1452 KB Time: 0 MS
Language: G++ Result: Accepted
*/
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn=+5;
char maps[maxn][maxn][maxn];
bool vis[maxn][maxn][maxn];
char op[10];
int n;
int a[10];
int dx[]={0,0,1,0,-1,0};
int dy[]={0,0,0,1,0,-1};
int dz[]={1,-1,0,0,0,0};
struct obje{
int x,y,z,steps;
obje(int x,int y,int z,int steps):x(x),y(y),z(z),steps(steps){}
bool operator<(const obje &a)const{
return steps>a.steps;
}
};
void bfs(){
priority_queue<obje>G;
G.push(obje(a[0],a[1],a[2],0));
while(!G.empty()){
obje e=G.top();
G.pop();
if(e.x<0||e.y<0||e.z<0||e.x>=n||e.y>=n||e.z>=n||maps[e.x][e.y][e.z]=='X'||vis[e.x][e.y][e.z])continue;
vis[e.x][e.y][e.z]=true;
if(e.x==a[3]&&e.y==a[4]&&e.z==a[5]){
printf("%d %d\n",n,e.steps);
return;
}
for(int i=0;i<6;i++){
int nx=e.x+dx[i];
int ny=e.y+dy[i];
int nz=e.z+dz[i];
G.push(obje(nx,ny,nz,e.steps+1));
}
}
printf("NO ROUTE\n");
}
int main(){
#ifndef ONLINE_JUDGE//本博客有介绍其用处
freopen("D://imput.txt","r",stdin);
#endif // ONLINE_JUDGE
while(~scanf("%s%d",op,&n)){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
scanf("%s",maps[i][j]);
}
}
for(int i=5;i>=0;i--){
scanf("%d",&a[i]);
}
scanf("%s",op);
bfs();
}
return 0;
}

Asteroids!-裸的BFS的更多相关文章

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

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

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

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

  3. 【BZOJ-1656】The Grove 树木 BFS + 射线法

    1656: [Usaco2006 Jan] The Grove 树木 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 186  Solved: 118[Su ...

  4. NOIP2003神经网络[BFS]

    题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神经网络的研究一直是当今 ...

  5. csu 1604 SunnyPig (bfs)

    Description SunnyPig is a pig who is much cleverer than any other pigs in the pigpen. One sunny morn ...

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

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

  7. ZOJ3865:Superbot(BFS) The 15th Zhejiang University Programming Contest

    一个有几个小坑的bfs 题目很长,但并不复杂,大概总结起来有这么点. 有t组输入 每组输入n, m, p.表示一个n*m的地图,每p秒按键会右移一次(这个等会儿再讲). 然后是地图的输入.其中'@'为 ...

  8. Day1:T3 bfs T4 树形DP

    T3:BFS 回看了一下Day1的T3...感觉裸裸的BFS,自己当时居然没有看出来... 同时用上升和下降两种状态bfs即可 这一题还要注意一个细节的地方,就是题目要求的是求往返的最优解 k=min ...

  9. hdu2612 Find a way BFS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2612 思路: 裸的BFS,对于Y,M分别进行BFS,求出其分别到达各个点的最小时间: 然后对于@的点, ...

随机推荐

  1. SQL Server分组查询某最大值的整条数据(包含linq写法)

    想实现如下效果,就是分组后时间最大的那一条数据: 1.SQL SELECT * FROM ( SELECT * , ROW_NUMBER() OVER ( PARTITION BY RIP_GUID ...

  2. 02.JSP内置对象

    一.内置对象:不再由用户进行实例化而可以直接使用的对象,一共九种,一定要清楚的记住每种内置对象的类型,以方便查询文档. 二.四种属性保存范围 1,  属性保存范围:指一个设置的对象,可以经过多少个其他 ...

  3. C# 判断文件是否文本文件

    在网上查了好多资料,大部分都是通过将文件读成二进制流,取前两个字节判断,比如.jpg的是255216.代码如下: ); i++; }return isTextFile; }catch (Excepti ...

  4. [转载] Linux的Top命令解析

    转载自http://www.jb51.net/LINUXjishu/34604.html.http://blog.csdn.net/hello_yang213/article/details/7455 ...

  5. protobuf/android 交叉编译笔记

    protobuf 交叉编译笔记 目标是使用 android ndk 的工具链编译出 android armeabi-v7a 可用的 protobuf 库. 交叉编译环境配置 windows 平台 下载 ...

  6. HTML基础--position 绝对定位 相对定位 锚点链接

    position 定位属性,检索对象的定位方式 一.语法:position:static /absolute/relative/fixed 取值: 1.static:默认值,无特殊定位,对象遵循HTM ...

  7. 2017年php面试题汇总

    1.http状态码 200 这个没有什么好说的,是代表请求被正常的处理成功了 302 代表临时重定向 400 400表示请求报文中存在语法错误.需要修改后再次发送 403 表明请求访问的资源被拒绝了. ...

  8. 将传统项目改造为SSM框架的项目

    首先 第一步改变传统dao层 先要再resource文件夹下创建一个applicationContext.xml  内容如下 关键代码     <!--        使spring扫描包下的所 ...

  9. centos6.9(Linux系统)安装VMware tools教程

    VMware tools是虚拟机上虚拟硬件的驱动,可以实现鼠标的无缝移出移入,剪贴板共享,共享文件夹等功能.很多的Linux系统初学者,在安装centos6.9系统时,没有安装VMware tools ...

  10. 设计模式-模板方法模式(Head First)

    参考书籍:Head First设计模式 什么是模板方法模式 定义:在一个方法中定义一个算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤. 怎 ...