hdu1010 Tempter of the Bone —— dfs+奇偶性剪枝
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010
Tempter of the Bone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 131057 Accepted Submission(s): 35308
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.
'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.
S.X.
..X.
..XD
....
3 4 5
S.X.
..X.
...D
0 0 0
YES
代码如下:
#include<stdio.h>//hdu1010 dfs+奇偶性剪枝
#include<stdlib.h> char map[][];
int n,m,t, wall, si, sj, di, dj;
int d[][] = {{, }, {, -}, {, }, {-, }}; int dfs(int i, int j, int step)
{
if(step == t)//如果最后一秒
{ //判断是否到达door
if(i == di && j == dj) return ;
else return ;
} if (i == di && j == dj )//如果到达door
{
//判断是否最后一秒
if (step == t) return ;
else return ;
} //奇偶性剪枝
int temp = t-step-abs(i - di) + abs(j - dj);
if( temp% )
return ; for (int k = ; k<; k++)
{
int x = i + d[k][];
int y = j + d[k][];
if (x>= && x<=n && y>= && y<=m && map[x][y] != 'X')
{
map[x][y] = 'X';
if(dfs(x, y, step + )) return ;
map[x][y] = '.';//回溯出口,记得复原(可能把'D'变成'.',但已经用didj保存其位置,所以没关系)
}
}
return ;
} int main()
{
while(scanf("%d%d%d",&n,&m,&t) &&m &&n &&t)
{
wall = ;
for (int i = ; i<=n; i++)
{
scanf("%s",map[i]+);
for (int j = ; j<=m; j++)
{
//用scanf(%c) 就出问题?
if (map[i][j] == 'S') { si = i; sj = j; }
if (map[i][j] == 'D') { di = i; dj = j;}
if (map[i][j] == 'X') { wall++; }
}
} map[si][sj] = 'X';
if (n * m - wall- < t)
{ //初始判断剩余的空格(记得减去初始位置)是否够走
puts("NO");
continue;
} if (dfs(si, sj, ))
puts("YES");
else
puts("NO");
}
return ;
}
hdu1010 Tempter of the Bone —— dfs+奇偶性剪枝的更多相关文章
- hdu - 1010 Tempter of the Bone (dfs+奇偶性剪枝) && hdu-1015 Safecracker(简单搜索)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 这题就是问能不能在t时刻走到门口,不能用bfs的原因大概是可能不一定是最短路路径吧. 但是这题要过除了细心 ...
- HDU1010:Tempter of the Bone(dfs+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 //题目链接 http://ycool.com/post/ymsvd2s//一个很好理解剪枝思想的博客 ...
- 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 搜索---奇偶性剪枝
Tempter of the Bone Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) ...
- M - Tempter of the Bone(DFS,奇偶剪枝)
M - Tempter of the Bone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- Tempter of the Bone(dfs奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 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(深搜+剪枝问题)
Tempter of the Bone Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission( ...
- hdu 1010 Tempter of the Bone (奇偶性剪枝)
题意:有一副二维地图'S'为起点,'D'为终点,'.'是可以行走的,'X'是不能行走的.问能否只走T步从S走到D? 题解:最容易想到的就是DFS暴力搜索,,但是会超时...=_=... 所以,,要有其 ...
随机推荐
- 网络流24T 太空飞行计划问题
题目背景 题目描述 W 教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利润.现已确定了一个可供选择的实验集合E={E1,E2,…,Em},和进行这些实验需要使用的 ...
- 创建Oracle数据库、数据库名与实例名与SID之间的关系(图文详解)
分类: Oracle(9) 版权声明:转载请注明出处 JmilkFan_范桂飓:http://blog.csdn.net/jmilk 目录(?)[+] 目录 目录 软件环境 前言 安装Oracle监听 ...
- linux下命令行的查找顺序
由下可知,linux通过$PATH的路径顺序,由左至由依次查找某个程序,如果有两个路径下都有这个程序,以先找到的为准 [rpc_server]$ which 23/usr/bin/which: no ...
- linux如和对其他用户隐藏进程?
Linux kernel 3.2以上,root用户可以设置内核,让普通用户看不到其它用户的进程.适用于有多个用户使用的系统.该功能由内核提供,因此本教程适用于Debian/Ubuntu/RHEL/Ce ...
- HashMap 和 Hashtable 的同和不同
综述 可以直接根据 hashcode 值判断两个对象是否相等吗?肯定是不可以的,因为不同的对象可能会生成相同的 hashcode 值.虽然不能根据 hashcode 值判断两个对象是否相等,但是可以直 ...
- 从零開始开发Android版2048 (二)获取手势信息
今天是尝试開始Android版2048小游戏的第二天.在今天,我主要学习了怎样获取用户在屏幕滑动的手势,以及对布局进行了一些小小的完好. 获取用户操作的手势(比方向左滑.向右滑等)主要用到了Gestu ...
- 翻翻git之---有用的欢迎页开源库 AppIntro
转载请注明出处:王亟亟的大牛之路 今天没有P1.直接进入正题 今天上的是一个帅帅的app滑动介绍页 . 为什么说帅? 作者对自己的内容是这么定义的 Make a cool intro for your ...
- 金山面试CDN
History 今天去金山网络面试的时候,被问到性能优化,我说了几个.最后说到了CDN,我说要尽量把静态的内容放置到CDN,可是为什么呢?面试官说既然你说到CDN.你就说说它的原理. 之前有看过,可是 ...
- source insight的查找功能
source insight是一款非常好的c语言的程序编辑器.方便对project管理,方便程序的阅读和编辑. 查找功能使用十分频繁.选项较多,与其他软件的查找功能也类似,以下对英文版的查找功能,做简 ...
- 没有IP地址的主机怎样保持IP层联通
在<两台不同网段的PC直连能否够相互ping通>一文中,我有点像在玩旁门左道,本文中.我继续走火入魔.两台机器,M1和M2,各自有一个网卡eth0,配置例如以下:M1的配置:eth0上不配 ...