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

咳咳  言归正传  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();
}
}

 

posted on 2015-04-23 19:36  毕竟我是王宇浩  阅读(146)  评论(0编辑  收藏  举报