zoukankan      html  css  js  c++  java
  • 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;
    }

  • 相关阅读:
    洛谷1001 A+B Problem
    怒刷洛谷记录
    前端开发工程师---技术路线图
    HTML5、微信、APP:创业寒冬只能选其一,该选哪个?
    eafier 簡單易用 HTML、CSS 網頁編輯器(可自動插入 Tag 標籤)
    <c ss高效开发实战>看完了,Bootstrap学习是关键
    【原创】CSS高效开发实战:CSS 3、LESS、SASS、Bootstrap、Foundation --读书笔记(5)使用放射渐变制作光影效果
    CSS高效开发实战:CSS 3、LESS、SASS、Bootstrap、Foundation --读书笔记(4)构造尺寸更灵活的背景
    CSS高效开发实战:CSS 3、LESS、SASS、Bootstrap、Foundation --读书笔记(3)线性渐变
    CSS高效开发实战:CSS 3、LESS、SASS、Bootstrap、Foundation --读书笔记(2)CSS3利用图层叠加实现多背景
  • 原文地址:https://www.cnblogs.com/crazyapple/p/2999472.html
Copyright © 2011-2022 走看看