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. Python中编码问题:u'\xe6\x97\xa0\xe5\x90\x8d' 类型的转为utf-8的解决办法

    相信小伙伴们遇到过类似这样的问题,python2中各种头疼的转码,类似u'\xe6\x97\xa0\xe5\x90\x8d' 的编码,直接s.decode()是无法解决编码问题.尝试了无数办法,都无法 ...

  2. 最小k个数

    题目 输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,. 思考 方法0: 直接排序然后返回前k个,最好的时间复杂度为 O(nlo ...

  3. jQuery实现checkbox即点即改,批量计数,以及中间遇到的坑

    最近要用jQuery实现一个批量删除操作,效果如下图 最终页面page.html,此页面使用了bootstrap和jQuery,如果没有需要下载一下 <!DOCTYPE html> < ...

  4. MySQLbase

    /*多行注释*/-- 单行注释-- 创建用户: CREATE USER '用户名'[@'主机名'] IDENTIFIED BY '密码'-- 主机名可以为空,省略主机名表示默认权限为%, 所有主机都可 ...

  5. Python+selenium打开网页

    东西都安装好了,是不是都迫不及待的想要运行一个程序呢? 不过不幸的是,在正式编程打开网页之前,我们还需要做一件事:下载驱动. 据说,在很久之前的selenium1和2中,驱动是被内嵌在selenium ...

  6. 运维必须掌握的150个Linux命令

    线上查询及帮助命令(1个)man 目录操作命令(6个)ls tree pwd mkdir rmdir cd 文件操作命令(7个)touch cp mv rm ln find rename 文件查看及处 ...

  7. 页面第一次加载,JS没有效果,刷新一下就好了

    问题详述:页面跳转的时候,第一个第二个页面都没有问题,跳到第三个页面,JS脚本没有起作用,刷新一下就好了. 1.猜测:第一个页面和第二个页面的JS,会对第三个页面产生影响,(因为之前没有这个问题,只改 ...

  8. C#写的较完美验证码通用类

    using System; using System.Collections; using System.ComponentModel; using System.Data; using System ...

  9. 入坑第二式 golang入坑系统

    史前必读: 这是入坑系列的第二式,如果错过了第一式,可以去gitbook( https://andy-zhangtao.gitbooks.io/golang/content/ )点个回放,看个重播.因 ...

  10. Unity3D游戏GC优化总结---protobuf-net无GC版本优化实践

    protobuf-net优化效果图 protobuf-net是Unity3D游戏开发中被广泛使用的Google Protocol Buffer库的c#版本,之所以c#版本被广泛使用,是因为c++版本的 ...