hdu 1240 Asteroids!
来源:互联网 发布:淘宝店铺怎么取名 编辑:程序博客网 时间:2024/05/11 15:36
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
思路:说的简单一点就是三维搜索,O是可以走的地方, X是不可以走的地方。接下来给你两个坐标,问你是否可以走得到。如果可以走的到,首先输出START 后面的数,然后输出步数,如果不能走到的话,那就输出NO ROUTE。
AC代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>using namespace std;char map[20][20][20];int dr[6][3] = {{0, 0, -1},{0, 0, 1},{1, 0, },{-1, 0, 0},{0, 1, 0},{0, -1, 0}};int vis[20][20][20];int sx, sy, sz, ex, ey, ez;int b;struct node{ int x, y, z, step;}p;void bfs(){ p.x = sz, p.y = sx, p.z = sy, p.step = 0; queue<node>Q; Q.push(p); vis[sx][sy][sz] = 1; node now, next; int flag = 0; while(!Q.empty()) { now = Q.front(); Q.pop(); for(int i = 0; i < 6; i++) { next.x = now.x + dr[i][0]; next.y = now.y + dr[i][1]; next.z = now.z + dr[i][2]; if(next.x >= 0&&next.x < b&&next.y >= 0&&next.y < b&&next.z >= 0&&next.z < b&&map[next.x][next.y][next.z]!='X'&&vis[next.x][next.y][next.z]==0) { if(map[next.x][next.y][next.z]=='O') { next.step = now.step + 1; vis[next.x][next.y][next.z] = 1; Q.push(next); } if(next.x==ez&&next.y==ex&&next.z==ey) { flag = 1; printf("%d %d\n",b, now.step + 1); return ; } } } } if(flag == 0) printf("NO ROUTE\n");}int main(){ char a[10], a1[10]; while(gets(a)) { int len = strlen(a); b = a[len - 1] - '0'; memset(vis, 0, sizeof(vis)); for(int i = 0; i < b; i++) { for(int j = 0; j < b; j++) { cin >> map[i][j]; } } /*for(int i = 0; i < b; i++) { for(int j = 0; j < b; j++) { for(int k = 0; k < b; k++) { printf("%c",map[i][j][k]); } printf("\n"); } printf("\n"); }*/ scanf("%d%d%d%d%d%d",&sx, &sy, &sz, &ex, &ey, &ez); scanf("%s",a1); if(sx==ex&&sy==ey&&sz==ez) { printf("%d 0\n",b); getchar(); continue; } bfs(); getchar(); } return 0;}
- hdu 1240 Asteroids!
- HDU-1240-Asteroids!
- hdu 1240 Asteroids!
- hdu 1240 Asteroids!
- Hdu 1240 Asteroids!
- hdu 1240 Asteroids!
- hdu 1240 Asteroids!
- HDU 1240 Asteroids!
- hdu 1240 Asteroids BFS
- HDU 1240 Asteroids!
- hdu 1240 Asteroids!
- hdu-1240-Asteroids!
- HDU 1240 Asteroids!
- hdu 1240 Asteroids!bfs
- Asteroids! HDU 1240
- HDU 1240 Asteroids!(BFS)
- hdu 1240 Asteroids!(BFS)
- HDU 1240 Asteroids!
- poj-1703(并查集) Parity game
- Python---64位的windows系统中python的下载与安装
- 驱动面试题
- Axure RP 7.0注册码
- 快速调用打电话界面 隐式意图
- hdu 1240 Asteroids!
- docker note
- byte b = (byte)130; 结果为-126,为什么?
- 集成华为手机Push SDK的小结
- 原型与原型链
- 记账管家绿色版 V1.0
- (转)Android高级学习之RecylerView和ListView的区别
- material design drawerlayout 出现的toolbar上的入口自定义
- Centos7网络配置-解决无法联网