zoukankan      html  css  js  c++  java
  • 亡命逃窜---三维搜索

    呵呵,哈哈,一次A  !!!!    今年比赛就算我一个人去打 我也冲银保铜 !!!

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<iostream>
    #include<algorithm>
    #include<queue>
    #include<vector>
    #include<set>
    #include<stack>
    #include<string>
    #include<sstream>
    #include<map>
    #include<cctype>
    using namespace std;
    int a,b,c,a1[55][55][55],visited[55][55][55],mark;
    int b1[6][3]={1,0,0,-1,0,0,0,0,1,0,0,-1,0,1,0,0,-1,0};
    struct node
    {
        int x,y,z,step;
    };
    queue<node>Q;
    void DFS(int x,int y,int z)
    {
        node q={x,y,z,0};
        visited[x][y][z]=1;
        Q.push(q);
        while(!Q.empty())
        {
            node e=Q.front();
            Q.pop();
            for(int i=0;i<6;i++)
            {
                if(mark)
                    return ;
                q.x=e.x+b1[i][0],q.y=e.y+b1[i][1],q.z=e.z+b1[i][2];
                if(q.x>=0&&q.x<a&&q.y>=0&&q.y<b&&q.z>=0&&q.z<c&&!visited[q.x][q.y][q.z]&&a1[q.x][q.y][q.z]!=1)   //  没有 超出 范围   并且 没有访问 且  不是墙
                {
                    visited[q.x][q.y][q.z]=1;
                    q.step=e.step+1;
                    Q.push(q);
                    if(a-1==q.x&&b-1==q.y&&q.z==c-1)
                    {
                        a1[a-1][b-1][c-1]=q.step;
                        mark=1;
                    }
                }
            }
        }
    }
    int main()
    {
        int t,n;
        scanf("%d",&n);
        while(n--)
        {
            scanf("%d%d%d%d",&a,&b,&c,&t);
            for(int i=0;i<a;i++)
                for(int j=0;j<b;j++)
                for(int q=0;q<c;q++)
            {
                scanf("%d",&a1[i][j][q]);
            }
            memset(visited,0,sizeof(visited));
           // a1[a-1][b-1][c-1]=-1;
           mark=0;
            DFS(0,0,0);
            if(mark&&a1[a-1][b-1][c-1]<=t)
                printf("%d
    ",a1[a-1][b-1][c-1]);
            else
                printf("-1
    ");
        }
        return 0;
    }

      `

  • 相关阅读:
    PHP新的垃圾回收机制:Zend GC详解
    SSH隧道技术简介
    mysql主从延迟
    非root配置linux下vim
    PHP 中的 9 个魔术方法
    PHP内核介绍及扩展开发指南—Extensions 的编写(下)
    PHP内核介绍及扩展开发指南—Extensions 的编写
    php 扩展开发
    php opcode
    rsa 数学推论
  • 原文地址:https://www.cnblogs.com/A-FM/p/5332202.html
Copyright © 2011-2022 走看看