HDU1240
来源:互联网 发布:淘宝贷款欠款 编辑:程序博客网 时间:2024/06/03 23:41
1.题目描述:
Asteroids!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5410 Accepted Submission(s): 3443
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 | We have carefully selected several similar problems for you: 1072 1372 1238 1401 1195
2.题意概述:
给你一个三维空间起点和终点,只能走‘O’,要你求最短路径,走不到则输出NO ROUTE。
3.解题思路:
直接从起点开始bfs即可。
4.AC代码:
#include <bits/stdc++.h>#define INF 0x3f3f3f3f#define maxn 100100#define lson root << 1#define rson root << 1 | 1#define lent (t[root].r - t[root].l + 1)#define lenl (t[lson].r - t[lson].l + 1)#define lenr (t[rson].r - t[rson].l + 1)#define N 1111#define eps 1e-6#define pi acos(-1.0)#define e exp(1.0)using namespace std;const int mod = 1e9 + 7;typedef long long ll;typedef unsigned long long ull;char mp[11][11][11];bool vis[11][11][11];int dir[6][3] = { {1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {-1, 0, 0}, {0, -1, 0}, {0, 0, -1} };int n, sx, sy, sz, ex, ey, ez, ans;struct node{int x, y, z, step;node(int a, int b, int c, int d) { x = a; y = b; z = c; step = d; }};void bfs(){memset(vis, 0, sizeof(vis));queue<node> q;q.push(node(sx, sy, sz, 0));while (!q.empty()){node cur = q.front();q.pop();vis[cur.x][cur.y][cur.z] = 1;if (cur.x == ex && cur.y == ey && cur.z == ez)ans = min(ans, cur.step);if (cur.step > ans)continue;for (int i = 0; i < 6; i++){int dx = cur.x + dir[i][0];int dy = cur.y + dir[i][1];int dz = cur.z + dir[i][2];if (dx >= 0 && dx < n && dy >= 0 && dy < n && dz >= 0 && dz < n && !vis[dx][dy][dz] && mp[dx][dy][dz] != 'X')q.push(node(dx, dy, dz, cur.step + 1));}}}int main(){#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);long _begin_time = clock();#endifwhile (~scanf("START %d\n", &n)){for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)scanf("%s", mp[i][j]);scanf("%d %d %d\n%d %d %d\nEND\n", &sz, &sy, &sx, &ez, &ey, &ex);ans = INF;bfs();if (ans < INF)printf("%d %d\n", n, ans);elseputs("NO ROUTE");}#ifndef ONLINE_JUDGElong _end_time = clock();printf("time = %ld ms.", _end_time - _begin_time);#endifreturn 0;}
阅读全文
0 0
- hdu1240
- hdu1240
- hdu1240
- HDU1240
- hdu1240
- HDU1240
- HDU1240 Asteroids!
- hdu1240 Asteroids!
- HDU1240:Asteroids!
- hdu1240 Asteroids!
- hdu1240 Asteroids!
- HDU1240:Asteroids
- hdu1240 (bfs)
- hdu1240广搜
- HDU1240:Asteroids!(BFS)
- hdu1240 Asteroids! (BFS)
- Asteroids!(hdu1240,dfs)
- hdu1240——Asteroids!
- IP相关的基础知识
- Appium移动自动化测试(四)--one demo
- 比QQ更炫酷的'选项弹窗'动画
- Linux基本命令操作
- 4.4Webservice
- HDU1240
- java转义mysql关键字
- java中的Serializable浅谈
- noi.openjudge_P8462大盗阿福
- httpwatch初级使用
- Android Studio使用Kotlin时Execution failed for task ':app.compileDebugKotlin'.问题
- Java-IO流
- Choose the best route dijst算法
- iOS: 如何判断代码运行在DEBUG还是RELEASE模式下?