HDU1240:Asteroids!
来源:互联网 发布:剑三捏脸数据截图 编辑:程序博客网 时间:2024/05/30 04:30
点击打开题目链接
Asteroids!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2625 Accepted Submission(s): 1765
Problem Description
You're in space.
You want to get home.
There are asteroids.
You don't want to hit them.
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.
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.
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 1O0 0 00 0 0ENDSTART 3XXXXXXXXXOOOOOOOOOXXXXXXXXX0 0 12 2 1ENDSTART 5OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOXXXXXXXXXXXXXXXXXXXXXXXXXOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO0 0 04 4 4END
Sample Output
1 03 4NO ROUTE
Source
South Central USA 2001
Recommend
zf
=====================================题目大意=====================================
从一个规格为 N X N X N 的空间中找到从起始点(A,B,C)到目标点(D,E,F)的最短路径长度。
=====================================算法分析=====================================
简单BFS,在普通2D搜索题的基础上稍加修改即可。
======================================代码========================================
#include<queue>#include<cstdio>#include<cstring>using namespace std;#define DIS(P) Dis[P.lv][P.row][P.col] //坐标对应的Dis值#define MAP(P) Map[P.lv][P.row][P.col] //坐标对应的Map值#define SAME(A,B) ((A.lv==B.lv)&&(A.row==B.row)&&(A.col==B.col)) //相同坐标#define LEGCORD(P) ((0<=P.lv&&P.lv<N)&&(0<=P.row&&P.row<N)&&(0<=P.col&&P.col<N)) //合法坐标const int Dir[6][3]={{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}};int N,Dis[15][15][15];char Map[15][15][15];struct COORD { int lv,row,col; }S,E;COORD MoveCoord(COORD Cur,int N) //坐标Cur朝方向N移动一次后得到的坐标 {COORD tmp;tmp.lv =Cur.lv +Dir[N][0];tmp.row=Cur.row+Dir[N][1];tmp.col=Cur.col+Dir[N][2];return tmp;}void BFS(){memset(Dis,-1,sizeof(Dis));DIS(S)=0;queue<COORD> q;for(q.push(S);!q.empty();q.pop()){COORD cur=q.front(); if(SAME(cur,E)) { printf("%d %d\n",N,DIS(E)); return;}for(int n=0;n<6;++n){COORD tmp=MoveCoord(cur,n);if(LEGCORD(tmp)&&MAP(tmp)!='X'&&DIS(tmp)==-1){DIS(tmp)=DIS(cur)+1;q.push(tmp);}}}printf("NO ROUTE\n");}void ReaData(){for(int i=0;i<N;++i){for(int j=0;j<N;++j){scanf("%s",Map[i][j]);}}scanf("%d%d%d",&S.col,&S.row,&S.lv);scanf("%d%d%d",&E.col,&E.row,&E.lv);scanf("%*s");}int main(){while(scanf("%*s%d",&N)==1){ReaData();BFS();}return 0;}
- HDU1240 Asteroids!
- hdu1240 Asteroids!
- HDU1240:Asteroids!
- hdu1240 Asteroids!
- hdu1240 Asteroids!
- HDU1240:Asteroids
- HDU1240:Asteroids!(BFS)
- hdu1240 Asteroids! (BFS)
- Asteroids!(hdu1240,dfs)
- hdu1240——Asteroids!
- HDU1240 Asteroids!(BFS)
- ACM 搜索 hdu1240 Asteroids!
- hdu1240 Asteroids!--DFS & BFS
- HDU1240 Asteroids!(BFS)
- BFS---HDU1240 Asteroids!
- HDU1240(BFS)Asteroids!
- Hdu1240 - Asteroids! - 广度优先搜索
- HDU1240 - Asteroids! (广搜)
- Oracle 12c 新特性之 Multitenant Architecture (二)
- VS2008 C++ 项目怎样添加“依赖”、“库目录”和“包含目录”
- hdu 1863 畅通工程
- 复制drawable 中的文件(图片或者数据库都可以)到sd卡
- centOS 6.4 (64bit) 安装 Python 2.7.5
- HDU1240:Asteroids!
- 题目1501:最大连续子序列乘积
- poj3624(01背包)
- 目录的相关命令
- Unity 墙遮挡人物时变为半透明
- 大数的阶乘
- Goahead 在Chrome跳转top.location.href 导致卡死问题
- 【Ogre开发】之一:Ogre sdk的安装以及示例代码的编译和运行
- UNIX环境高级编程——Linux终端设备详解