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

  • 相关阅读:
    podium服务器端的微前端开发框架
    几个java proxy servlet 工具
    Presto Infrastructure at Lyft
    cube.js 通过presto-gateway 进行连接
    presto-gateway nodejs client
    presto-gateway 试用以及docker 镜像制作
    presto-gateway lyft 团队开源的prestodb 的负载均衡、代理、网关工具
    Singer 修改tap-s3-csv 支持minio 连接
    plotly-dash 简单使用(一)
    smashing 三方widgets 使用
  • 原文地址:https://www.cnblogs.com/kuangbin/p/2118108.html
Copyright © 2011-2022 走看看