• hdu 1010 Tempter of the Bone(bfs)


    hdu 1010 Tempter of the Bone

    http://acm.hdu.edu.cn/showproblem.php?pid=1010

    Problem Description
    The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried desperately to get out of this maze.

    The maze was a rectangle with sizes N by M. There was a door in the maze. At the beginning, the door was closed and it would open at the T-th second for a short period of time (less than 1 second). Therefore the doggie had to arrive at the door on exactly the T-th second. In every second, he could move one block to one of the upper, lower, left and right neighboring blocks. Once he entered a block, the ground of this block would start to sink and disappear in the next second. He could not stay at one block for more than one second, nor could he move into a visited block. Can the poor doggie survive? Please help him.
     

    Input
    The input consists of multiple test cases. The first line of each test case contains three integers N, M, and T (1 < N, M < 7; 0 < T < 50), which denote the sizes of the maze and the time at which the door will open, respectively. The next N lines give the maze layout, with each line containing M characters. A character is one of the following:

    'X': a block of wall, which the doggie cannot enter; 
    'S': the start point of the doggie; 
    'D': the Door; or
    '.': an empty block.

    The input is terminated with three 0's. This test case is not to be processed.
     

    Output
    For each test case, print in one line "YES" if the doggie can survive, or "NO" otherwise.
     

    Sample Input
    4 4 5 S.X. ..X. ..XD .... 3 4 5 S.X. ..X. ...D 0 0 0
     

    Sample Output
    NO YES

    //剪枝深度搜索

    #include<iostream>
    #include<cmath>
    using namespacestd;
    int
    m,n,t;
    char
    map[10][10];
    bool
    mark[10][10];
    int
    ex,ey,flag;
    int
    cx[]={0,0,1,-1};
    int
    cy[]={-1,1,0,0};
    void
    dfs(intsx,intsy,intstep)
    {

        int
    i;
        if
    (flag)  return;
        if
    (sx==ex&&sy==ey&&step==t)
        {

            flag=1;
            return
    ;
        }

        int
    temp=(t-step)-abs(sx-ex)-abs(sy-ey);
        if
    (temp<0||temp%2!=0)
            return
    ;
        for
    (i=0;i<4;i++)
        {

            int
    dx=cx[i]+sx;
            int
    dy=cy[i]+sy;
            if
    (dx>=0&&dx<m&&dy>=0&&dy<n&&!mark[dx][dy]&&map[dx][dy]!='X')
            {

                mark[dx][dy]=1;
                dfs(dx,dy,step+1);
                if
    (flag)return;
                mark[dx][dy]=0;
            }
        }
    }

    int
    main()
    {

        while
    (~scanf("%d%d%d",&m,&n,&t))
        {

            if
    (n==0&&m==0&&t==0)
                break
    ;
            int
    i,j,sx,sy;
            for
    (i=0;i<m;i++)
            {
        
                getchar();
                for
    (j=0;j<n;j++)
                {

                    scanf("%c",&map[i][j]);
                    if
    (map[i][j]=='S')
                    {

                        sx=i;
                        sy=j;
                    }

                    else if
    (map[i][j]=='D')
                    {

                        ex=i;
                        ey=j;
                    }
                }
            }

            getchar();
            flag=0;
            memset(mark,0,sizeof(mark));
            mark[sx][sy]=1;
            dfs(sx,sy,0);
            if
    (flag)
                puts("YES");
            else

                puts("NO");
        }

        return
    0;
    }

  • 相关阅读:
    Centos7部署Django
    CentOS7 常用命令
    window安装django-auth-ldap
    解决group by分组默认获取id最小的一条数据
    js基础之if判断
    java操作word转pdf多选框问题(linux服务器下)
    震惊,男默女泪,使用nginx代理,并进行ip拦截
    高德地图在marker里设置自定义属性
    angular项目启动错误
    本地连接虚拟机内的kafka遇到的问题
  • 原文地址:https://www.cnblogs.com/crazyapple/p/2999472.html
Copyright © 2020-2023  润新知