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. 在centos上安装jenkins

    摘要: 本篇介绍了如何在linux服务器上安装jenkins 一:使用war安装 官网地址:https://jenkins.io/doc/ Guided Tour This guided tour w ...

  2. Ajax 跨域 异步 CORS

    HTTP access control (CORS) 核心在于使用定制(添加新的header)HTTP header让浏览器和服务器有更多的相互了解,从而决定一个请求或者响应成功还是失败   对于一个 ...

  3. sass学习--在htm文件中使用

    一.导语 最近的战狼2好火爆啊,每天看战狼2的票房一路高飙,我估计比吴京还开心.看了这部戏的拍摄过程,除了敬佩就是踏实,是的,吴京是电影圈隔了这么久后能踏踏实实做电影的了,纯属个人见解,不喜请忽略.. ...

  4. PHPMailer < 5.2.21 - Local File Disclosure(CVE-2017-5223)

    CVE-2017-5223 :PHPMailer < 5.2.21 - Local File Disclosure 本文主要介绍一下PHPMailer < 5.2.21 - Local F ...

  5. ThinkPHP模版验证要注意的地方

    Model页面 <?php class LoginModel extends Model { //protected $tableName = 'userinfo'; //表名和model不一致 ...

  6. 常见sql注入原理详解!

    1.首先我们创建一个mysqli的链接 /**数据库配置*/ $config = ['hostname'=>"localhost", 'port'=>"330 ...

  7. 【分享】jQuery无插件实现 鼠标拖动图片切换 功能

    前言 我就想随便叨逼叨几句,爱看就看几句,不爱看就直接跳过看正文就好啦~ 这个方法是仿写页面时我自己研究出来,可能有比我更简单的方法. 但我不管,因为我没查我不知道,我就觉得我的最好啦,耶耶耶~ 效果 ...

  8. 在Linux机器上安装telnet命令

    一.查看本机是否安装       telnet #rpm -qa | grep telnet     如果什么都不显示,说明没有安装telnet 二.开始安装 yum install xinetd y ...

  9. 编程语言 : Java的动态Web解决方案泛谈

    文章概述 最近发现很久前一股脑地学习框架,发觉越发迷糊.知道了框架只是暂时的,重点是基础的技术.该文大篇幅回顾Servlet技术栈和简要的MVC框架. 至于为什么学J2EE,额,大家都用框架,可框架也 ...

  10. LKD: Chapter 5 System Call

    在Linux中,处理器所作的事可以归纳为3种情况: 1.In user-space, executing user code in a process; 2.In kernel-space, in p ...