hdu1240三维bfs最短路轻松1A

#define DeBUG
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <set>
#include <sstream>
#include <map>
#include <bitset>
using namespace std ;
#define zero {0}
#define INF 2000000000
#define EPS 1e-6
typedef long long LL;
const double PI = acos(-1.0);
inline int sgn(double x)
{
    return fabs(x) < EPS ? 0 : (x < 0 ? -1 : 1);
}
struct Node
{
    int x, y, z;
    int step;
    Node(int a,int b,int c,int s)
    {
        x=a;
        y=b;
        z=c;
        step=s;
    }
};
int dir[6][3] = {0, 0, 1, 0, 0, -1, 0, 1, 0, 0, -1, 0, 1, 0, 0, -1, 0, 0};
int main()
{
#ifdef DeBUGs
    freopen("C:\\Users\\Sky\\Desktop\\1.in", "r", stdin);
#endif
    char start[10];
    char end[10];
    int n;
    while (scanf("%s%d", start, &n) + 1)
    {
        char mp[20][20][20] = zero;
        bool vis[20][20][20] = zero;
        for (int z = 0; z < n; z++)
        {
            for (int i = 0; i < n; i++)
            {
                scanf("%s", mp[z][i]);
            }
        }
        int sx, sy, sz;
        int ex, ey, ez;
        scanf("%d%d%d", &sx, &sy, &sz);
        scanf("%d%d%d", &ex, &ey, &ez);
        scanf("%s", end);

        queue<Node>Q;
        Node node(sx,sy,sz,0);
        Q.push(node);
        bool flag=false;
        while(!Q.empty())
        {
            node=Q.front();
            Q.pop();

            if(node.x==ex&&node.y==ey&&node.z==ez)
            {
                flag=true;
                break;
            }
            int x,y,z;
            for(int i=0;i<6;i++)
            {
                x=node.x+dir[i][0];
                y=node.y+dir[i][1];
                z=node.z+dir[i][2];
                if(x<0||y<0||z<0||x>=n||y>=n||z>=n||vis[z][y][x]||mp[z][y][x]=='X')
                    continue;
                Node now(x,y,z,node.step+1);
                vis[z][y][x]=true;
                Q.push(now);
            }
        }
        if(flag)
            printf("%d %d\n",n,node.step);
        else
            printf("NO ROUTE\n");

    }

    return 0;
}
好开森
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值