博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1240 Asteroids!
阅读量:4597 次
发布时间:2019-06-09

本文共 3995 字,大约阅读时间需要 13 分钟。

Asteroids!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 5581    Accepted Submission(s): 3548

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
 
AC代码(BFS+QUEUE)
1 #include
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 const int MAX=13; 8 struct pot 9 {10 int x,y,k;11 };12 struct data13 {14 int time; char ch;15 };16 data arr[MAX][MAX][MAX];17 int x1,y1,k1,x2,y2,k2;18 int dir[6][3]={
{
1,0,0},{
0,1,0},{-1,0,0},{
0,-1,0},{
0,0,-1},{
0,0,1}};19 int n;20 int BFS()21 {22 pot beg={x1,y1,k1};23 queue
que;24 que.push(beg);25 while(!que.empty())26 {27 pot cur=que.front();28 que.pop();29 if(cur.x==x2&&cur.y==y2&&cur.k==k2)30 return arr[cur.k][cur.x][cur.y].time;31 for(int i=0;i<6;i++)32 {33 pot next={cur.x+dir[i][0],cur.y+dir[i][1],cur.k+dir[i][2]};34 if(next.x>=0&&next.x
=0&&next.y
=0&&next.k
arr[cur.k][cur.x][cur.y].time+1)39 {40 arr[next.k][next.x][next.y].time=arr[cur.k][cur.x][cur.y].time+1;41 que.push(next);42 }43 }44 }45 return -1;46 }47 int main()48 {49 //ifstream in("data.txt");50 string sign;51 while(cin>>sign>>n)52 {53 int k,i,j;54 for(k=0;k
>arr[k][i][j].ch;59 arr[k][i][j].time=0;60 }61 cin>>x1>>y1>>k1>>x2>>y2>>k2;62 cin>>sign;63 int result=BFS();64 if(result>=0)65 cout<
<<" "<
<

 

转载于:https://www.cnblogs.com/zhaopeng938/p/7920189.html

你可能感兴趣的文章
团队每日冲刺04
查看>>
oracle中的decode的使用
查看>>
PHP生成中文验证码并检测对错实例
查看>>
数据库经典练习题整理
查看>>
android与javaee通信:登录界面超级简化版
查看>>
Nhibernate3.3.3sp1基础搭建测试
查看>>
Python之模块与包
查看>>
C++中获取文件大小的几种途径汇总~
查看>>
JavaScript原始基础
查看>>
JDBC_基础6步骤- 及优化
查看>>
WCM重启报数据库启动错误
查看>>
totoise svn误将桌面作为checkout路径,界面一堆?
查看>>
java写"\n"写入到txt文本用记事本打开出现黑框解决方案
查看>>
第三章例3-7
查看>>
心得五
查看>>
react antD moment
查看>>
MySql创建指定字符集的数据库
查看>>
bzoj 3172 AC自动机
查看>>
rabbitmq
查看>>
解决Latex中Itemize距离过大的问题
查看>>