• hdu 1240 Asteroids!


    点击打开链接

    因为没令str[d][e][f]='O',导致wrong了无数次。。。而且郁闷了好几天。。

    #include"stdio.h"
    #include"string.h"
    #include"queue"
    #include"ctype.h"
    using namespace std;
    int map[15][15][15];
    int flag,a,b,c,d,e,f,n;
    char str[15][15][15];
    int dir[6][3]={{1,0,0},{-1,0,0},{0,1,0},{0,1,0},{0,0,1},{0,0,-1}};
    struct node
    {
        int x,y,z,step;
    };
    int judge(int x,int y,int z)
    {
        if(x>=0&&x<n&&y>=0&&y<n&&z>=0&&z<n
            &&map[x][y][z]==0&&str[x][y][z]=='O')
            return 1;
        return 0;
    }
    void bfs()
    {
        int i,x,y,z;
        queue<node>q;
        node cur,next;
        memset(map,0,sizeof(map));
        cur.x=a;
        cur.y=b;
        cur.z=c;
        cur.step=0;
        q.push(cur);
        map[a][b][c]=1;
        if(a==d&&b==e&&c==f)
        {
            printf("%d 0\n",n);
            return ;
        }
        while(!q.empty())
        {
            cur=q.front();
            q.pop();
            for(i=0;i<6;i++)
            {
                next.x=x=cur.x+dir[i][0];
                next.y=y=cur.y+dir[i][1];
                next.z=z=cur.z+dir[i][2];
                if(judge(x,y,z))
                {
                    map[x][y][z]=1;
                    next.step=cur.step+1;
                    if(x==d&&y==e&&z==f)
                    {
                        printf("%d %d\n",n,next.step);
                        return ;
                    }
                    q.push(next);
                }
            }
        }
        printf("NO ROUTE\n");
    }
    int main()
    {
        int i,j;
        char s[15],t[15];
        while(scanf("%s %d",s,&n)==2)
        {
            for(i=0;i<n;i++)
                for(j=0;j<n;j++)
                    scanf("%s",str[i][j]);
            scanf("%d%d%d",&a,&b,&c);
            scanf("%d%d%d",&d,&e,&f);
    str[d][e][f]='O';//这个千万不忘啊!!
            bfs();
            scanf("%s",t);
            
        }
        return 0;
    }



  • 相关阅读:
    boost库
    DISALLOW_COPY_AND_ASSIGN
    汇编语言入门
    gflags
    Segmentation Fault
    ubuntu16.04_cuda9.0_opencv3.4_cudnn_v7_caffe
    make: aarch64-himix100-linux-gcc: Command not found
    gtest
    glog
    [Go]go语言实战-go版本的supervisord编译安装与运行
  • 原文地址:https://www.cnblogs.com/yyf573462811/p/6365403.html
Copyright © 2020-2023  润新知