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. 利用echarts highcharts 实现自定义地图 关系图效果 侧边3D柱形图饼图散点图

    github 地址:  https://https://github.com/Gengshaoxuan/medataMap github 地址:  https://https://github.com ...

  2. Scrum Meeting Alpha - 5

    Scrum Meeting Alpha - 5 NewTeam 2017/10/20 地点:主楼与4号楼之间的走廊2楼 任务反馈 团队成员 完成任务 计划任务 安万贺 完成了对班级作业部分的API的包 ...

  3. Power BI本地部署(10月正式版)

    Power BI安装环境要求 Windows 7/Windows Server 2008 R2 或更高版本 .NET 4.5 或更高版本 Internet Explorer 9 或更高版本 内存 (R ...

  4. Python之元类

    类型对象负责创建对象实例,控制对象行为.那么类型对象又由谁来创建呢? 元类(metaclass)——类型的类型 New-Style Class的默认类型是type >>> class ...

  5. CSharpGL(47)你好,Framebuffer!

    CSharpGL(47)你好,Framebuffer! Framebuffer对象(FBO)是一种复杂的OpenGL对象.使用自定义的framebuffer,可以实现离屏渲染,进而实现很多高级功能,例 ...

  6. 图片转换base64数据上传,并且实现预览的简便方法

    对于很多新手来说,实现上传图片并且预览功能,都会感到不知所可,然后开始在网站搜索各种各样的图片上传预览插件,但是有的时候我们只是想简单的实现判断格式,以及预览的功能,使用插件的话,会使得项目的资源空间 ...

  7. Maven启动Java Web工程,8081和8086端口号被占用

    Maven启动Java Web工程, <!-- 配置tomcat插件 --> <build> <plugins> <plugin> <groupI ...

  8. DNS:域名系统

    概述: DNS的作用在于将域名转换为对应的IP地址. DNS名字空间和UNIX文件系统相似,也是树形结构.以"."结尾的域名称为FQDN(Full Qualified Domain ...

  9. [最短路][模版]P1346 电车

    题目描述 在一个神奇的小镇上有着一个特别的电车网络,它由一些路口和轨道组成,每个路口都连接着若干个轨道,每个轨道都通向一个路口(不排除有的观光轨道转一圈后返回路口的可能).在每个路口,都有一个开关决定 ...

  10. EntityFramework6与EntityFrameworkCore的区别

    EntityFramework6 EF6 是一个久经考验的数据库访问技术,发展多年,拥有许多特性,并且成熟稳定.2008年EF作为 .Net 3.5 Sp1 和Visual Studio 2008 S ...