Asteroids! 我不是女神ヾ 2022-06-12 03:15 110阅读 0赞 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 题意:一个三维空间地图,求起点到终点最少的步数 #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; }
相关 poj 题目3041 Asteroids (最小点覆盖) [http://poj.org/problem?id=3041][http_poj.org_problem_id_3041] 最小覆盖: 最小覆盖要求用最少的点(X集合 不念不忘少年蓝@/ 2022年12月22日 02:25/ 0 赞/ 144 阅读
相关 POJ 3041-Asteroids(二分图匹配) Asteroids <table> <tbody> <tr> <td><strong>Time Limit:</strong> 1000MS</t 曾经终败给现在/ 2022年09月24日 05:29/ 0 赞/ 5 阅读
相关 BOJ 3160 Asteroids //二分图水题 Asteroids Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on P 古城微笑少年丶/ 2022年08月10日 14:45/ 0 赞/ 125 阅读
相关 POJ 3041 Asteroids //简单二分图 Asteroids <table> <tbody> <tr> <td><strong>Time Limit:</strong> 1000MS</t 左手的ㄟ右手/ 2022年08月10日 14:38/ 0 赞/ 183 阅读
相关 poj 2225 Asteroids!【BFS】 Asteroids! <table> <tbody> <tr> <td><strong>Time Limit:</strong> 1000MS</ r囧r小猫/ 2022年08月10日 09:59/ 0 赞/ 2 阅读
相关 Asteroids! You're in space. You want to get home. There are asteroids. You don't want to h 我不是女神ヾ/ 2022年06月12日 03:15/ 0 赞/ 111 阅读
相关 leetcode 735. Asteroid Collision 行星碰撞 + 类似括号配对 + 栈的典型应用 We are given an array asteroids of integers representing asteroids in a row. For each a 妖狐艹你老母/ 2022年06月03日 09:44/ 0 赞/ 163 阅读
相关 Poj 3041 Asteroids + Poj 2226 Muddy Fields(二分图与一类选方格题目) Poj 3041 Asteroids 思路:把方阵看做一个特殊的二分图(以行列分别作为两个顶点集V1、V2,其中| V1|=| V2|) 然后把每行x或者每列y看成一个点 秒速五厘米/ 2021年11月22日 21:01/ 0 赞/ 259 阅读
相关 PANGU---Planet and Asteroid Natural scene Generation Utility PANGU是由英国dundee邓迪大学开发的一款行星、小行星自然环境仿真软件 https://www.star-dundee.com/products/pangu-plane ╰+哭是因爲堅強的太久メ/ 2021年07月17日 00:33/ 0 赞/ 274 阅读
还没有评论,来说两句吧...