Asteroids!
来源:互联网 发布:大数据text下载 编辑:程序博客网 时间:2024/05/29 17:43
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.
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 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.
START 1O0 0 00 0 0ENDSTART 3XXXXXXXXXOOOOOOOOOXXXXXXXXX0 0 12 2 1ENDSTART 5OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOXXXXXXXXXXXXXXXXXXXXXXXXXOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO0 0 04 4 4END
1 03 4NO ROUTE
题意:一个三维空间地图,求起点到终点最少的步数
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<queue>#include<algorithm>using namespace std;int n,sx,sy,sz,ex,ey,ez;char map1[11][11][11];int vis[11][11][11];int dx[]= {-1,0,1,0,0,0};int dy[]= {0,0,0,0,1,-1};int dz[]= {0,1,0,-1,0,0};struct A{ int x,y,z,step;};int bfs(int x,int y,int z){ queue<A> Q; A f,g; f.x=x; f.y=y; f.z=z; f.step=0; vis[x][y][z]=1; Q.push(f); while(!Q.empty()) { f=Q.front(); Q.pop(); if(f.x==ex&&f.y==ey&&f.z==ez) { return f.step; } for(int i=0; i< 6; i++) { g.step=f.step; g.x=f.x+dx[i]; g.y=f.y+dy[i]; g.z=f.z+dz[i]; if(g.x>=0&&g.y>=0&&g.z>=0&&g.x<n&&g.y<n&&g.z<n&&!vis[g.x][g.y][g.z]&map1[g.x][g.y][g.z]!='X') { vis[g.x][g.y][g.z]=1; g.step=f.step+1; Q.push(g); } } } return -1;}int main(){ char str[10];//int n;和全局变量冲突了 while(~scanf("%s %d",str,&n)) { memset(vis,0,sizeof(vis)); for(int i=0; i<n; i++) for(int j=0; j<n; j++) { getchar(); for(int l=0; l<n; l++) scanf("%c",&map1[j][l][i]); } scanf("%d %d %d %d %d %d",&sx,&sy,&sz,&ex,&ey,&ez); scanf("%s",str); int ans=bfs(sx,sy,sz); if(ans>=0) printf("%d %d\n",n,ans); else printf("NO ROUTE\n"); } return 0;}
阅读全文
0 0
- Asteroids!
- Asteroids!
- Asteroids
- Asteroids
- Asteroids!
- Asteroids
- Asteroids
- Asteroids
- Asteroids!
- Asteroids!
- Asteroids
- Asteroids
- Asteroids
- Asteroids
- Asteroids
- HDU1240 Asteroids!
- hdu1240 Asteroids!
- POJ3041 Asteroids
- laravel框架session使用教程
- A. Unimodal Array(段增减性
- springMvc无法访问静态文件
- 复选框选中事件
- python3.6 安装builtwith模块
- Asteroids!
- 快速幂模板(病毒)
- CLion,debug模式程序正常运行,run模式下出现停止运行
- 一个小白对oop c++ 访问private内容的理解
- ScrollView嵌套ViewPager冲突
- 头文件引用中<>与“”的区别
- MySQL Cluster 7.3.7+CentOS7集群配置入门 MySQL双管理节点配置入门
- 网页小知识---onblur,onfocus和表单提交的两种方式
- JavaMath方法、服务器与Tomcat安装与配置步骤