三位坐标的建立

#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
struct node{
    int x,y,z;
    int step;
};
int move1[6][3]={-1,0,0,1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1};
int cheak[12][12][12];
char s[]={"START "};
char f[]={"END"};
char space[12][12][12];
int n,x,y,z,g;
int bfs(int a,int b,int c)
{
    queue<node>q;
    node now;
    now.x=c;
    now.y=a;
    now.z=b;
    now.step=0;
    q.push(now);
    while(!q.empty())
    {
        now=q.front();
        q.pop();
        if(now.x==z+1&&now.y==x+1&&now.z==y+1)
        {
            g=1;
            return now.step;
        }
        for(int i=0;i<6;i++)
        {
            int dx=now.x+move1[i][0];
            int dy=now.y+move1[i][1];
            int dz=now.z+move1[i][2];
            if(dx>=1&&dx<=n&&dy>=1&&dy<=n&&dz>=1&&dz<=n&&cheak[dx][dy][dz]==0&&space[dx][dy][dz]=='O')
            {
                node next;
                next.x=dx;
                next.y=dy;
                next.z=dz;
                cheak[dx][dy][dz]=1;
                next.step=now.step+1;
                q.push(next);
            }
        }
    }
}
int main()
{
    int a1,b1,c1,w;
    while(cin>>s>>n)
    {
        g=0;
        memset(space,0,sizeof(space));
        memset(cheak,0,sizeof(cheak));
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
            {
                cin>>(space[i][j]+1);
            }
        cin>>a1>>b1>>c1;
        cin>>x>>y>>z;
        cin>>f;
        w=bfs(a1+1,b1+1,c1+1);
        if(g==1)
        {
            cout<<n<<" "<<w<<endl;
        }
        else
        {
        cout<<"NO ROUTE"<<endl;
        }
    } 
}

 

转载于:https://www.cnblogs.com/Leozi/p/10835235.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值