HDU 1010 Temper of the bone(深搜+剪枝)
Tempter of the Bone
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 15 Accepted Submission(s) : 9
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
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
'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
Sample Input
4 4 5
S.X.
..X.
..XD
....
3 4 5
S.X.
..X.
...D
0 0 0
Sample Output
NO
YES
Author
Source
#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int dr[][]={{,},{,},{-,},{,-}};
int f[][];
char mp[][];
int sx,sy,tx,ty,t,n,m,i,j;
int check(int x,int y)
{
if (x>= && x<n && y>= && y<m && mp[x][y]!='X' && !f[x][y]) return ;
else return ;
}
int dfs(int x,int y,int time)
{
if (time== && x==tx && y==ty)
return ;
for(int i=;i<;i++)
{
int xx=x+dr[i][];
int yy=y+dr[i][];
if (check(xx,yy))
{
f[xx][yy]=;
if (dfs(xx,yy,time-)) return ;
f[xx][yy]=;
}
}
return ;
} int main()
{
while(scanf("%d%d%d",&n,&m,&t) && n!=)
{
for(i=;i<n;i++)
{
scanf("%s",&mp[i]);
for(j=;j<m;j++)
if (mp[i][j]=='S') sx=i,sy=j;
else if (mp[i][j]=='D') tx=i,ty=j;
}
if (t==)
{
if (sx!=tx && sy!=ty) printf("NO\n");
else if (sx==tx && sy==ty) printf("YES\n");
continue;
}
if (abs(tx-sx)+abs(ty-sy)>t || (t-abs(tx-sx)-abs(ty-sy))%!=) {printf("NO\n");continue;} memset(f,,sizeof(f));
f[sx][sy]=;
if (dfs(sx,sy,t)) printf("YES\n");
else printf("NO\n");
} return ;
}
HDU 1010 Temper of the bone(深搜+剪枝)的更多相关文章
- hdu 1010 Tempter of the Bone 深搜+剪枝
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- HDU 1010 Tempter of the Bone(深度+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 题意:就是给出了一个迷宫,小狗必须经过指定的步数到达出口,并且每个格子只能走一次. 首先先来介绍一下奇偶性 ...
- HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四 ...
- hdu - 1010 Tempter of the Bone (dfs+奇偶性剪枝) && hdu-1015 Safecracker(简单搜索)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 这题就是问能不能在t时刻走到门口,不能用bfs的原因大概是可能不一定是最短路路径吧. 但是这题要过除了细心 ...
- hdu.1010.Tempter of the Bone(dfs+奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdu1010 Tempter of the Bone(深搜+剪枝问题)
Tempter of the Bone Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission( ...
- HDU 1010 Tempter of the Bone (DFS+剪枝)
题意:从S走到D,能不能恰好用T时间. 析:这个题时间是恰好,并不是少于T,所以用DFS来做,然后要剪枝,不然会TEL,我们这样剪枝,假设我们在(x,y),终点是(ex,ey), 那么从(x, y)到 ...
- Hdu1010Tempter of the Bone 深搜+剪枝
题意:输入x,y,t.以及一个x行y列的地图,起点‘S’终点‘D’地板‘.’墙壁‘X’:判断能否从S正好走t步到D. 题解:dfs,奇偶性减枝,剩余步数剪枝. ps:帮室友Debug的题:打错了两个字 ...
- hdu 1010 Tempter of the Bone (奇偶性剪枝)
题意:有一副二维地图'S'为起点,'D'为终点,'.'是可以行走的,'X'是不能行走的.问能否只走T步从S走到D? 题解:最容易想到的就是DFS暴力搜索,,但是会超时...=_=... 所以,,要有其 ...
随机推荐
- mysql的字符串处理函数
一.简明总结ASCII(char) 返回字符的ASCII码值BIT_LENGTH(str) 返回字符串的比特长度CONCAT(s1,s2…,sn) 将s1,s2…,sn连接成字符串CONCAT_WS( ...
- 洛谷-A+B Problem-洛谷的第一个任务
题目描述 Description 输入两个整数a,b,输出它们的和(a,b<=10^9) 输入输出格式 Input/output 输入格式:两个整数以空格分开输出格式:一个数 输入输出样例 ...
- 关于springboot启动时候报错:springboot Failed to parse configuration class [Application]
把运行的java类放在一个package下后就不再提示这个错误. 使用的ide是intellij,之前也有因为没有创建package报错的经历,可能这是intellij必须的
- PHP 流程
登录页面 <body> <form action="loginchuli.php" method="post"> <div> ...
- Python 学习笔记12
不积跬步,无以至千里.不积小流,无以成江河. 当我觉得沮丧.绝望的时候,就疯狂的敲代码,这样会好受一点. 今天和昨天敲了两天的小程序,算是对python的具体语法规则有个初步的手熟. http://w ...
- 移动前端不得不了解的HTML5 head 头标签(中下篇)
SEO 优化部分 页面标题<title>标签(head 头部必须) <title>your title</title> 页面关键词 keywor ...
- Git单独checkout子目录
http://schacon.github.io/git/git-read-tree.html#_sparse_checkout Existing Repository If you already ...
- python 字符转换
我们所看到的“明文字符串”,都是经过编码(比如ASCII.Uncoded.UTF-8.GB-2312等)后呈现在我们面前的. 文本中“3082”想要“所见到所得”到内存中处理,必须decode('he ...
- OC-之AFNetworking与ASIHTTPRequest对比
一.底层实现 1.AFN的底层实现基于OC的NSURLConnection和NSURLSession 2.ASI的底层实现基于纯C语言的CFNetwork框架 3.因为NSURLConnection和 ...
- SMO 的环境
Microsoft SQL Server System CLR Types - http://go.microsoft.com/fwlink/?LinkId=123721&clcid=0x40 ...