Tempter of the Bone(dfs+奇偶剪枝)
Tempter of the Bone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 94669 Accepted Submission(s):
25669
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.
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.
doggie can survive, or "NO" otherwise.
S.X.
..X.
..XD
....
3 4 5
S.X.
..X.
...D
0 0 0
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;
char map[][];
bool vis[][];
int dx[]={,,-,},dy[]={,-,,};
int n,m,t;
int sx,sy,ex,ey;
bool flag;
bool dfs(int x,int y,int tim)
{
if(flag) return ;
if(x<||y<||x>=n||y>=m||vis[x][y]==||tim>t||map[x][y]=='X')
return ;
if(tim<t&&map[x][y]=='D') return ;
int w=abs(x-ex)+abs(y-ey);
if(t-tim<w) return ;
int tem=w-abs(t-tim);
if(tem>||tem%) return ;
if(tim==t&&map[x][y]=='D') {flag=;return ;}
for(int i=;i<;i++)
{
vis[x][y]=;
int nx=x+dx[i];
int ny=y+dy[i];
dfs(nx,ny,tim+);
vis[x][y]=;
}
return ;
}
int main()
{
freopen("in.txt","r",stdin);
while(scanf("%d%d%d",&n,&m,&t))
{
getchar();
int tim=,z=;
flag=;
if(n==&&m==&&t==) break;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
scanf("%c",&map[i][j]);
if(map[i][j]=='S')
{
sx=i,sy=j;
}
if(map[i][j]=='D')
{
ex=i,ey=j;
}
// if(map[i][j]=='X') z++;
}
getchar();
}
//if(n*m-z<t){printf("NO\n");continue;}
memset(vis,,sizeof(vis));
dfs(sx,sy,);
if(flag) printf("YES\n");
else printf("NO\n");
}
}
Tempter of the Bone(dfs+奇偶剪枝)的更多相关文章
- 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 ...
- Tempter of the Bone(dfs奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- M - Tempter of the Bone(DFS,奇偶剪枝)
M - Tempter of the Bone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四 ...
- hdu1010 Tempter of the Bone —— dfs+奇偶性剪枝
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Ja ...
- hdu Tempter of the Bone (奇偶剪枝)
学习链接:http://www.ihypo.net/1554.html https://www.slyar.com/blog/depth-first-search-even-odd-pruning.h ...
- hdu1010Tempter of the Bone(dfs+奇偶剪枝)
题目链接:pid=1010">点击打开链接 题目描写叙述:给定一个迷宫,给一个起点和一个终点.问是否能恰好经过T步到达终点?每一个格子不能反复走 解题思路:dfs+剪枝 剪枝1:奇偶剪 ...
- 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
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- hdoj--1010<dfs+奇偶剪枝>
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目描述:在n*m的矩阵中,有一起点和终点,中间有墙,给出起点终点和墙,并给出步数,在该步数情况 ...
随机推荐
- Java学习笔记--多线程
rollenholt的博文:http://www.cnblogs.com/rollenholt/archive/2011/08/28/2156357.html 弹球例子: 0. 创建Bounce框架 ...
- Scala学习笔记--枚举
枚举 scala不用关注枚举的特别语法,取而代之的是标准库中的类, scala.Enumeration 想要创建新的枚举,只需要拓展这个类的对象即可 object Color extends Enum ...
- 使用jQuery来检测远程图片文件是否存在
使用jQuery来检测远程图片文件是否存在 最近为我的憨豆人笑园添加图片功能时,遇到了这个问题,用户可以填写一个远程的图片地址,也可以上传一个本地图片.为了不浪费服务器的资源,我们需要在客户端先对用户 ...
- softlayerFastUploadVHDtoBS
Object Storage Uploader Overview We’ve recently added the option to import customer-supplied Virtual ...
- Uninstall or Disable Java on a Mac
You can run Java apps in two ways. The first is to run Java applets inside your Web browser with a p ...
- 男同胞爱小秘籍--作为爱他的女朋友了几天C规划
各位男同胞,不知道你的女朋友没有在过去的一问天,你这个问题~~ 场景重现: 女友:"今天天气不错." 你们:"对" 女友:"今天是我们知道它的最初几天 ...
- 关于vi不正常退出产生的swp文件
关于vi不正常退出产生的swp文件 非正常关闭vi编辑器时会生成一个.swp文件 关于swp文件 使用vi,经常可以看到swp这个文件,那这个文件是怎么产生的呢,当你打开一个文件,vi就会生成这么 ...
- [Python][自己写的杀病毒脚本]
电脑里的HTML都插入了一段VB病毒代码..只能自己手动清除了..发现Python确实好用 import os import re; Root = ["H:"]; for root ...
- Tcp 数据对象传输接口对象设计
输入是一个对象inputObj,接口对象.Send(inputObj),对端接收之后解包成outputObj(与inputObj应相同),触发onPackageReceive事件 事件 public ...
- C#几种截取字符串的方法小结 (摘抄)
1.根据单个分隔字符用split截取 例如 string st="GT123_1"; string[] sArray=st.split("_"); 即可得到sA ...