Tempter of the Bone

时间:2022-09-11 15:57:37
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
题意:小狗找出口,给你一个n*m的地图和小狗,门的位置,让你小狗能否刚好在t时到达门口;
解题思路:刚开始想的是用广搜求出最小时间,如果最小时间
另外还可以加一个剪枝条件,当然了不加这个也能AC,(n*m-s<=t),t过大的时候肯定不能按时到达了;
感悟:深搜好些但是,剪枝不好写啊,不剪枝就会超时,好烦的!
代码:
#include

#include

#include

#include

#include

#define maxn 205

using namespace std;

int visit[maxn][maxn];//这个是记录步数的不是记录走没走的不能用布尔型

char mapn[maxn][maxn];

int n,m,t,direction[4][2]={{1,0},{-1,0},{0,1},{0,-1}};

int sx,sy,dx,dy;

bool flag;

void dfs(int x,int y,int time)

{

   
if(x<1||x>n||y<1||y>m)//边界

       
return;

   
if(flag==1)

       
return;

   
if(x==dx&&y==dy&&time==t)//找到D了

    {

       
if(time=t)

           
flag=1;

       
return;

    }

    int
temp=(t-time)-abs(x-dx)-abs(y-dy);//奇偶性剪枝

   

   
if(temp<0||temp&1)  return;

   

   

    for(int
i=0;i<4;i++)

    {

       
int x1=x+direction[i][0];

       
int y1=y+direction[i][1];

       
if(mapn[x1][y1]!='X')

       
{

           
mapn[x1][y1]='X';

           
dfs(x1,y1,time+1);

           
mapn[x1][y1]='.';//不满足条件的话就返回

       
}

    }

   
return;

}

int main()

{

    int
s=0;

   
//freopen("in.txt", "r", stdin);

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

{

       
flag=s=0;

       
for(int i=1;i<=n;i++)

       
{

           
for(int j=1;j<=m;j++)

           
{

               
scanf("%c",&mapn[i][j]);

               
if(mapn[i][j]=='S')

               
{

                   
sx=i;

                   
sy=j;//狗的位置

               
}

               
if(mapn[i][j]=='D')

               
{

                   
dx=i;

                   
dy=j;//门的位置

               
}

               
if(mapn[i][j]=='X')

                   
s++;

           
}

           
scanf("\n");

       
}

       
mapn[sx][sy]='X';

       
memset(visit,0,sizeof(visit));

       
//for(int i=1;i<=n;i++)

       
//{

       
//    for(int
j=1;j<=m;j++)

       
//    {

       
//       
printf("%c",mapn[i][j]);

       
//    }

       
//   
printf("\n");

       
//}

       
if (n*m-s<=t)//提前判断t过大的情况避免再去搜

       
{

           
printf("NO\n");

           
continue;

       
}

       
dfs(sx,sy,0);

       
//printf("最少走 %d 秒 有 %d 秒\n",ans,t);

       
if(flag)

           
printf("YES\n");

       
else

           
printf("NO\n");

    }

}

Tempter of the Bone的更多相关文章

  1. hdu&period;1010&period;Tempter of the Bone&lpar;dfs&plus;奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  2. ZOJ 2110 Tempter of the Bone

    Tempter of the Bone Time Limit: 2 Seconds      Memory Limit: 65536 KB The doggie found a bone in an ...

  3. hdu 1010&colon;Tempter of the Bone(DFS &plus; 奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  4. HDU 1010 Tempter of the Bone --- DFS

    HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...

  5. Hdu 1010 Tempter of the Bone 分类: Translation Mode 2014-08-04 16&colon;11 82人阅读 评论&lpar;0&rpar; 收藏

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  6. hdoj 1010 Tempter of the Bone【dfs查找能否在规定步数时从起点到达终点】【奇偶剪枝】

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  7. Tempter of the Bone(dfs&plus;奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  8. hdu 1010 Tempter of the Bone 深搜&plus;剪枝

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  9. Tempter of the Bone&lpar;dfs奇偶剪枝&rpar;

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  10. ZOJ 2110 Tempter of the Bone&lpar;条件迷宫DFS&comma;HDU1010&rpar;

    题意  一仅仅狗要逃离迷宫  能够往上下左右4个方向走  每走一步耗时1s  每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次  问狗是否有可能逃离这个迷宫 直接DFS  直道找到满足条件的路径 ...

随机推荐

  1. html5 requestAnimationFrame制作动画:旋转风车

    详细内容请点击 在以往,我们在网页上制作动画效果的时候,如果是用javascript实现,一般都是通过定时器和间隔来实现的,出现HTML5之后,我们还可以用CSS3 的transitions和anim ...

  2. 正确理解SQL Server的许可证&lpar;转&rpar;

    今天在论坛上看到有人讨论如果使用SQL Server作为SEPM的后台数据库,需要多少个CAL的问题:   If I do have to use SQL Server what type of li ...

  3. Luogu5058 &lbrack;ZJOI2004&rsqb;嗅探器

    $Luogu5058 [ZJOI2004]嗅探器 给定一张 \(n\) 个点, \(m\) 条边的无向图,和两点 \(s,\ t\) ,求 \(s\to t\) 编号最小的必经点(排除 \(s,\ t ...

  4. 一、iOS开发环境搭建

    前置条件 1. 必要:一台装有Mac OS X操作系统的电脑:经济允许的话可以买一部Mac book:否则的话,可以试试黑苹果或虚拟机. 2.必要:一个有可用的Apple ID:免费,在Apple的官 ...

  5. 软Raid5制作

    以raid5为例: 1.添加4块磁盘要求:容量.转速.接口一样的硬盘. 2.创建分区并修改ID[root@localhost ~]# fdisk /dev/sdb[root@localhost ~]# ...

  6. git 详细教程和常用操作指令

    git 内部工作原理图 如上图,git 一般可以分为三个区:工作区.暂存区.版本库,通常类似 git add等命令都是与index 暂存区的交互,git commit指令则是 index 与版本库的交 ...

  7. call 和 apply

    call和apply作用一样,都是为了转移this,区别在于传入参数的方式不同. this指当前方法所在的对象,如果方法的外面没有对象,则默认是window.由于闭包虽在调用的方法中,但是在创建的时候 ...

  8. 2018&period;08&period;22 codves2370 小机房的树(lca&plus;树上差分)

    传送门 一道板子题. 直接树链剖分维护树上lca然后差分就行了. 代码: #include<bits/stdc++.h> #define N 50005 #define lc (p< ...

  9. SwipeRefreshLayout的高度测量

    感谢此作者的分享 http://www.cnblogs.com/linjzong/p/5221604.html 若SwipeRefreshLayout的子布局为一个线性布局LinearLayout, ...

  10. word前页与后页页码断开

    方法一:以Word2013为例:1. 光标移动到目录页的最后一行,从“页面布局”选项卡“分隔符”中选择“下一页”类型的“分节符”,删除多余的行.分页符等(图1): 2. 双击正文任意一页的页眉/页脚区 ...