Asteroids!

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7008 Accepted Submission(s): 4336

Problem 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

Source
South Central USA 2001

问题链接:HDU1240 POJ2225 Asteroids!
问题简述:(略)
问题分析
    这是一个三维BFS问题。
    需要注意坐标系,输入数据并非是按x、y和z的坐标,所以输入坐标时需要做特殊处理。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* HDU1240 POJ2225 Asteroids! */#include <iostream>
#include <queue>using namespace std;const int DN = 6;
int dx[] = {1, -1, 0, 0, 0, 0};
int dy[] = {0, 0, 1, -1, 0, 0};
int dz[] = {0, 0, 0, 0, 1, -1};const int N = 10;
char map[N][N][N + 1];
int n;
struct Node {int lvl, x, y, z;} sn, en, t, nt;void bfs()
{queue<Node> q;sn.lvl = 0;map[sn.x][sn.y][sn.z] = 'X';q.push(sn);while(!q.empty()) {t = q.front();q.pop();if(t.x == en.x && t.y == en.y && t.z == en.z) {cout << n << " " << t.lvl << endl;return;}for(int i = 0; i < DN; i++) {nt = t;nt.x += dx[i];nt.y += dy[i];nt.z += dz[i];if(0 <= nt.x && nt.x < n && 0 <= nt.y && nt.y < n && 0 <= nt.z && nt.z <n&& map[nt.x][nt.y][nt.z] != 'X') {map[nt.x][nt.y][nt.z] = 'X';nt.lvl++;q.push(nt);}}}cout << "NO ROUTE" << endl;
}int main()
{ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);string s;while(cin >> s >> n) {for(int i = 0; i < n; i++)for(int j = 0; j < n; j++)for(int k = 0; k < n; k++)cin >> map[i][j][k];cin >> sn.z >> sn.y >> sn.x;cin >> en.z >> en.y >> en.x;cin >> s;bfs();}return 0;
}

HDU1240 POJ2225 Asteroids!【BFS】相关推荐

  1. 【BFS】魔板(c++基础算法)

    本专栏上一篇:[BFS]八数码问题(c++基础算法) 目录 一.读题 ①题面 ②题意 三.做题 ①算法原理 ②算法实现 Ⅰ三种基本操作 Ⅱ操作序列 Ⅲ输出 Ⅳ一个特殊情况 四.AC代码 最后 一.读题 ...

  2. POJ 3414 Pots【BFS】+ Python

    原题链接: 3414 -- Pots 参考资料:POJ 3414 - Pots | 眈眈探求 POJ 3414 Pots[BFS][图搜] - it610.com 一 特别注意: 1. 每一种操作对应 ...

  3. 【枚举】【二分答案】【分块答案】【BFS】【最大流】【Dinic】bzoj1189 [HNOI2007]紧急疏散evacuate...

    [法一]枚举Time(0~N*M): S->'.'(1); 'D'->T(Time); '.'->'D'(dis(用BFS预处理,注意一旦到达'D',BFS就不能继续扩展了,注意di ...

  4. nyoj 284 坦克大战【bfs】

    坦克大战 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 Many of us had played the game "Battle city" i ...

  5. [kuangbin]专题二 搜索进阶 Escape HDU - 3533【BFS】

    [题目描述] The students of the HEU are maneuvering for their military training. The red army and the blu ...

  6. 【BFS】献给阿尔吉侬的花束(C++)

    [题目描述] 阿尔吉侬是一只聪明又慵懒的小白鼠,它最擅长的就是走各种各样的迷宫.今天它要挑战一个非常大的迷宫,研究员们为了鼓励阿尔吉侬尽快到达终点,就在终点放了一块阿尔吉侬最喜欢的奶酪.现在研究员们想 ...

  7. 【BFS】天棋哥哥大战AlphaGo 校OJ2395

    题目描述 3月15日,人机围棋大战巅峰对决在韩国首尔落下帷幕.五番棋的最后一局中,韩国著名棋手李世乭尽管与人工智能"AlphaGo"缠斗至官子阶段,但在双双进入读秒后最终还是投子认 ...

  8. 【bfs】WJ的逃离

    WJ(J)的逃离 题目大意: 有一个n×m的矩阵,*是不可走的,0是可走的,求1,1到n,m的最小转弯次数 原题: 题目描述 当WJ醒来时,发现自己被困在一个地图的左上角,幸好WJ有张图,并了解到出口 ...

  9. Bailian4129 变换的迷宫【BFS】

    4129:变换的迷宫 总时间限制: 1000ms 内存限制: 65536kB 描述 你现在身处一个R*C 的迷宫中,你的位置用"S" 表示,迷宫的出口用"E" ...

最新文章

  1. 多个SSH key对应多个Host: Github, Bitbucket
  2. 小米0扇区完整写入_真材实料霸榜DXOMARK,小米10系列凭三个卖点“感动人心”...
  3. Map 集合循环、遍历的 四 种方式
  4. Reusability1
  5. 二叉树后序遍历_二叉树后序遍历非递归实现
  6. IPython系统相关内容及其配置信息
  7. Noip2010提高组总结
  8. JavaScript 根据两点的经纬度坐标,计算实际的直线距离
  9. JAVA系列-设计模式-中介者模式
  10. 单独使用mybatis整合mysql案例
  11. 使用cmd命令查看WiFi密码
  12. 使用TFS2010管理敏捷项目生命周期-系列指南5 TFS 故事墙(Story Wall)-看板(Dashboard)-Workbrench使用
  13. 利用Pandas拆分Excel的单元格为多行并保留其他行的数据
  14. 【Vue3.0实战逐步深入系列】扩展投票功能基于elementui进行组件封装实现一个简单的问卷调查功能
  15. 【100个 Unity实用技能】☀️ | Unity中 检查当前设备网络状态 的几种方法整理
  16. 欧姆龙NJ/NX基于BaseNetwork Configuratore的 EIP通讯 方式
  17. 【渝粤教育】 广东开放大学21秋期末考试刑事诉讼法学10228k2
  18. php移动端url,织梦移动端跟PC端URL问题。 - 搜外SEO问答
  19. window.open 全屏展示
  20. imax6q项目:使用psplash制作开机动画

热门文章

  1. 云服务器更换系统要钱吗,云服务器可以更换系统吗
  2. mybatis添加方法可以传map吗_Mybatis创建方式二
  3. android view 屏幕外,安卓如何让View往屏幕外隐藏?
  4. oracle中 initcpa,oracle  11g rman备份
  5. 数组-scala数组与java的list的互转
  6. TensorFlow精进之路(十四):RNN训练MNIST数据集
  7. Linux C/C++开发环境搭建指针
  8. Tensorflow训练和预测中的BN层的坑(转)-训练和测试差异性巨大
  9. b+tree索引在MyIsam和InnoDB的不同实现方式
  10. java 分隔函数split(,-1)的用途