HDU 1240 Asteroids! 解题报告

//这道题做完我只有 三个感受  第一:坑; 第二 : 坑! 第三:还是坑!

咳咳  言归正传  WA了无数次之后才发现是输入进去时坐标时z, y, x的顺序输入的

题解   :  类似胜利大逃亡 只不过给你了起始坐标和终点坐标, 让你输出到达目标点所需最少步数;

输出时第一个输出时是START读入的map大小值n;第二个是所求步数

//细节:

1.读入:   读入时分别两次%S把没用的START 和 END读取掉;

2.输出时输出 三维坐标大小值n, 以及步数;

3.输入进去时开始点和结束点坐标都是z, y, x的顺序输入的!!!!!!!多加感叹号 因为这是这道题最坑的地方。

代码奉上:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define N 15
using namespace std;

typedef struct node
{
int x, y, z;
int step;
}ND;

ND s, e;
int dir[6][3] = {0,0,1, 0,1,0, 1,0,0, 0,0,-1, 0,-1,0, -1,0,0};
char maps[N][N][N];
char str[10];
int n;

void inPut()
{
int i, j;
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
scanf("%s", maps[i][j]);

scanf("%d %d %d", &s.z, &s.y, &s.x);
scanf("%d %d %d", &e.z, &e.y, &e.x);
scanf("%s", str);
}

void BFS()
{
int x, y, z, i;
ND v;
maps[s.x][s.y][s.z] = ‘X‘;

queue<ND>q;
q.push(s);

while(!q.empty())
{
s = q.front();
q.pop();
if(s.x == e.x && s.y == e.y && s.z == e.z)
{
printf("%d %d\n", n, s.step);
return;
}
for(i = 0; i < 6; i++)
{
x = s.x + dir[i][0];
y = s.y + dir[i][1];
z = s.z + dir[i][2];
if(x >= 0 && x < n && y >= 0 && y < n && z >= 0 && z < n && maps[x][y][z] == ‘O‘)
{
maps[x][y][z] = ‘X‘;
v = {x, y, z, s.step + 1};
q.push(v);
}
}
}

printf("NO ROUTE\n");
}

int main()
{
while(scanf("%s%d", str, &n) != EOF)
{
memset(maps, 0, sizeof(maps));
inPut();
BFS();
}
}

时间: 2024-08-25 17:48:59

HDU 1240 Asteroids! 解题报告的相关文章

hdu 1541 Stars 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目意思:有 N 颗星星,每颗星星都有各自的等级.给出每颗星星的坐标(x, y),它的等级由所有比它低层(或者同层)的或者在它左手边的星星数决定.计算出每个等级(0 ~ n-1)的星星各有多少颗. 我只能说,题目换了一下就不会变通了,泪~~~~ 星星的分布是不是很像树状数组呢~~~没错,就是树状数组题来滴! 按照题目输入,当前星星与后面的星星没有关系.所以只要把 x 之前的横坐标加起来就可以了

Valentine&#39;s Day Round 1001.Ferries Wheel(hdu 5174)解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5174 题目意思:给出 n 个人坐的缆车值,假设有 k 个缆车,缆车值 A[i] 需要满足:A[i−1]<A[i]<A[i+1](1<i<K).现在要求的是,有多少人满足,(他坐的缆车的值 + 他左边缆车的值) % INT_MAX == 他右边缆车的值. 首先好感谢出题者的样例三,否则真的会坑下不少人.即同一部缆车可以坐多个人.由于缆车的值是唯一的,所以可以通过排序先排出缆车的位置.求出

hdu 1963 Investment 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1963 题目意思:有 本金 money,还有一些股票的种类,第 i 种股票买入需要 value[i] 这么多钱,相应会有一定的利息interest[i],问经过若干年 year 后,每年都以最优的方案投资,总的资金有多少? 完全背包题,不过要看清楚 这句话:The value of a bond is always a multiple of $1 000,否则TLE了 1 #include <ios

hdu 1240:Asteroids!(三维BFS搜索)

Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3159    Accepted Submission(s): 2106 Problem Description You're in space.You want to get home.There are asteroids.You don't want to hit

HDU 1240——Asteroids!(三维BFS)POJ 2225——Asteroids

普通的三维广搜,需要注意的是输入:列,行,层 #include<iostream> #include<cstdio> #include<cstring> #include<queue> #include<algorithm> #define M 11 using namespace std; int dir[6][3]={{0,1,0},{0,-1,0},{1,0,0},{-1,0,0},{0,0,1},{0,0,-1}};//6个方向 int

hdu 超级楼梯 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2041 哦--对了,这些题读者可以直接忽略,我只是想练习一下自己薄弱的地方...... 题目意思我就不说了...自从昨晚问完乌冬兄一条DP题之后,“一体就知道系DP啦,而且仲好简单噶DP...”.就深感自己是如此地弱......可能有一段相当漫长的时间不会再找他了,毕竟一个喳喳对着一个区域赛银牌的人,自尊心作祟,而且,很大压力!我发现我好多不会......他好像以为我什么都会...... 这条题以前做

HDU 1240 Asteroids! (三维BFS)

Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4749    Accepted Submission(s): 3048 Problem Description You're in space. You want to get home. There are asteroids. You don't want to

HDU 1240.Asteroids!

Asteroids! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u SubmitStatusPracticeHDU 1240 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

HDU 1240 Asteroids!(BFS)

题目链接 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 fo