hdoj1010 Temperor of the bone

时间:2022-09-20 14:02:27

Tempter of the Bone

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

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
讲解:注意看清题的意思,题中说的是要,在正好的时间内,找到D,而不是小于或等于D
   特殊数据
6 6 37
S.....
......
......
......
......
D.....
NO
意思是在正好等于37 的时候 没有找到D
 #include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
int fangxiang[][]={{-,},{,},{,-},{,}};
const int MAX=;
char map[MAX][MAX];
int mark[MAX][MAX];
int n,m,t;
int start_x,start_y;
int end_x,end_y;
using namespace std;
bool DFS(int x,int y,int step)
{
int i,a,b;
if(map[x][y]=='D' && step==t)
return true;
if(x<||x>n || y< || y>m)//判断到最后了,还没有找到
return false;
if(step>=t)//剪枝1:当step>=T时还没有找到D点
return false;
if(t-step<(abs(x-end_x)+abs(y-end_y)))//剪枝2:还需要的步数比理论上的最短距离还小
return false;
if((t-step-(abs(x-end_x)+abs(y-end_y)))%!=) //剪枝3:比理论上的最短距离多出来的必是偶数
return false;
for(i=;i<;i++)
{
a=x+fangxiang[i][];
b=y+fangxiang[i][];
if(a<=n && a>= && b>= && b<=m && map[a][b]!='X' && !mark[a][b]) //判断三个条件:1.检验_x,_y是否越界。2.看vis[][]是否访问过。3.看map[][]是否是墙
{
mark[a][b]=;
if(DFS(a,b,step+))
return true;
else
mark[a][b]=;
}
}
return false;
}
int main()
{
int i,j;
while(cin>>n>>m>>t && n+m+t)
{
memset(mark,,sizeof(mark));
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
cin>>map[i][j];
if(map[i][j]=='S')
{
start_x=i;
start_y=j;
}
if(map[i][j]=='D')
{
end_x=i;
end_y=j;
}
}
}
mark[start_x][start_y]=;
if(DFS(start_x,start_y,))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return ;
}

hdoj1010 Temperor of the bone的更多相关文章

  1. HDOJ-1010 Tempter of the Bone(dfs&plus;剪枝)

    http://acm.hdu.edu.cn/showproblem.php?pid=1010 给出一个n*m的迷宫 X为墙 .为空地 S为起点 D为终点 给出时间T 每走一步花费一单位的时间 走过的空 ...

  2. 杭电1518 Square&lpar;构成正方形&rpar; 搜索

    HDOJ1518 Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. 玩儿转物联网IoT - 在Beagle Bone Black上运行node&period;js 程序

    物联网(IoT)技术方兴未艾,智能手环,智能血压计,智能眼镜甚至智能鞋垫都开始进入我们的生活,各种智能设备层出不穷,世界已经到了一个"人有多大胆,地有多大产"的时代,不玩儿点物联网 ...

  4. Tempter of the Bone

    Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he ...

  5. hdu 2602 Bone Collector(01背包)模板

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...

  6. hdu&ndash&semi;2369 Bone Collector II&lpar;01背包变形题&rpar;

    题意:求解01背包价值的第K优解. 分析: 基本思想是将每个状态都表示成有序队列,将状态转移方程中的max/min转化成有序队列的合并. 首先看01背包求最优解的状态转移方程:\[dp\left[ j ...

  7. 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 ...

  8. HDU 2602 Bone Collector WA谁来帮忙找找错

    Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...

  9. Bone Collector(01背包)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/N 题目: Description Many year ...

随机推荐

  1. &lbrack;2014&period;01&period;27&rsqb;wfPng 水印贴图组件 2&period;1

    支持载入bmp,jpg,gif,png四种格式等. 支持图片水印使用png格式,支持区域透明,半透明的png图片. 支持图片缩放. 支持画线.画矩形.画椭圆,画正圆等图形. 支持在图片上输出文字. 能 ...

  2. CAS 4&period;0&period;0RC 配置MD5验证功能

    配置内容同一样,只是增加一些配置. 因为cas已经默认就支持MD5加密验证,所以只是修改一下配置就可以了. <bean id="primaryAuthenticationHandler ...

  3. java和Discuz论坛实现单点登录,通过Ucenter(用户管理中心)

    标题有点问题,没有进行修改. 一 Discuz论坛搭建步骤 1:服务器环境配置 服务器要支持php语言+支持mysql 5.0以上的数据库 + Apache服务器(支持网站的一个服务器,通过域名的能访 ...

  4. Winform知识

    文档界面 分类: 1.单文档界面应用程序(SDI) 特点: 1.应用程序中SDI的所有窗体都彼此独立 2.多文档界面应用程序(MDI) 特点: 1.每个应用程序中只能有一个MDI父窗体,在父窗体中可以 ...

  5. MyEclipse下查看Java API帮助文档

    每次重装JDK或者升级JDK时,都会忘了如何使MyEclipse关联帮助文档.然后,再花十几分钟重新google搜索,麻烦! 首先下载Javadoc api帮助文档,google搜一下就行了. MyE ...

  6. &lbrack;置顶&rsqb; 自娱自乐6之Linux gadget驱动5(自编gadget驱动,包涵与之通讯的主机usb驱动,已调试通过)

    这个代码调试,你首先要保证你的udc驱动没用问题,这个有些矛盾,应为我本来要用gadget驱动来调试udc驱动,结果反过来了. 这是在zero基础改的,大概的改动 1. 去掉loop. 2. sink ...

  7. 开始 Python 之旅

    开始 Python 之旅 课程来源 本课程基于 Python for you and me 教程翻译制作,其中参考了 Python tutorial 和 The Python Standard Lib ...

  8. C&num; RSA加解密与验签,AES加解密,以及与JAVA平台的密文加解密

    前言: RSA算法是利用公钥与密钥对数据进行加密验证的一种算法.一般是拿私钥对数据进行签名,公钥发给友商,将数据及签名一同发给友商,友商利用公钥对签名进行验证.也可以使用公钥对数据加密,然后用私钥对数 ...

  9. Jq&lowbar;浏览器兼容性及其浏览器版本

    JQuery 中用 方法 jQuery.browser 来判断浏览器,返回值可以为: safari opera msie mozilla. 当然有时候我们还需要区分版本 这就要用到 jQuery.br ...

  10. 代码生成器 CodeSmith 的使用(二)

    在第一篇中,简单的介绍了 CodeSmith 的使用方法,这次做一个生成简单的数据库字段属性的模板.以下只粘贴主要的代码片段. <%-- Name: Copyright © Sun 2013-2 ...