• ACM HDU 1010 Tempter of the Bone


    Tempter of the Bone

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 23769    Accepted Submission(s): 6538


    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
     

    Author
    ZHANG, Zheng
     

    Source
     

    Recommend
    JGShining
     
    DFS  注意减枝
    #include<iostream>
    #include
    <queue>
    #include
    <string.h>
    #include
    <math.h>
    using namespace std;

    struct Node
    {
    int x,y,t;
    };
    int dx[]={1,0,-1,0};
    int dy[]={0,1,0,-1};
    int sx,sy;
    int N,M,T;
    char map[10][10];

    bool cnt;
    int num;
    void dfs(Node p)
    {
    if(cnt)return;
    if(p.x==sx&&p.y==sy&&p.t==T){cnt=true;return;}
    if(p.t>=T)return;
    int min=(int)(fabs((double)(p.x-sx))+fabs((double)(p.y-sy)));
    if(min>T-p.t)return;
    if(min%2!=(T-p.t)%2)return;
    //if(map[sx+1][sy]!='.'&&map[sx-1][sy]!='.'&&map[sx][sy+1]!='.'&&map[sx][sy-1]!='.')return;
    if(p.x==sx&&p.y==sy)return;
    Node tmp;
    for(int i=0;i<4;i++)
    {
    tmp.x
    =p.x+dx[i];
    tmp.y
    =p.y+dy[i];
    tmp.t
    =p.t+1;
    if(cnt||tmp.x<1||tmp.x>N||tmp.y<1||tmp.y>M||map[tmp.x][tmp.y]=='X')continue;
    if(tmp.x==sx&&tmp.y==sy&&tmp.t==T){cnt=true;return;}
    char ch=map[tmp.x][tmp.y];
    map[tmp.x][tmp.y]
    ='X';
    dfs(tmp);
    map[tmp.x][tmp.y]
    =ch;

    }
    }
    int main()
    {
    Node p;
    while(scanf("%d %d %d",&N,&M,&T)!=EOF)
    {
    if(N==0&&M==0&&T==0)break;
    memset(map,
    0,sizeof(map));
    num
    =0;
    for(int i=1;i<=N;i++)
    for(int j=1;j<=M;j++)
    {
    cin
    >>map[i][j];

    if(map[i][j]=='S')
    {p.x
    =i;p.y=j;p.t=0;}
    else if(map[i][j]=='D')
    {sx
    =i;sy=j;}
    else num++;
    }
    if(num<T-1) {cout<<"NO"<<endl;continue;}
    map[p.x][p.y]
    ='X';
    cnt
    =false;
    dfs(p);
    if(cnt) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    }
    return 0;
    }

  • 相关阅读:
    hadoop(五)scp命令copy文件和配置(完全分布式准备二)|7
    hadoop(四)centos7克隆|静态ip|机器名|映射关系|别名配置(完全分布式准备一)|6
    大数据及hadoop简要概念
    hadoop(三)伪分布模式hdfs文件处理|5
    Hadoop(二) 单节点案例grep和wordcount|4
    centos7 ip/映射/机器名变更/克隆(克隆后配置修改)|2
    centos7 NAT链接配置(静态ip/修改网卡名为eth0)|1
    Hadoop(一) centos7 jdk安装,hadoop安装|3
    hive常用函数五
    hive常用函数四
  • 原文地址:https://www.cnblogs.com/kuangbin/p/2118108.html
Copyright © 2020-2023  润新知