M - Tempter of the Bone(DFS,奇偶剪枝)
M - Tempter of the Bone
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
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
Sample Output
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std; char map[][];
bool vis[][];
int s_x,s_y,e_x,e_y;
int a,b,t,ok; bool check(int x,int y)
{
if (x<=||x>a||y<=||y>b)
return ;
if (map[x][y]=='X'||vis[x][y]||ok)
return ;
return ;
} void dfs(int x,int y,int time)
{
vis[x][y]=;
//printf("(%d,%d)\n",x,y);
if (x==e_x&&y==e_y&&time==t)//满足条件到终点
{
ok=;
return;
} int temp=t-time-(abs(x-e_x)+abs(y-e_y)); if (temp<)//剩余步数小于 0
return; int n_x,n_y; n_x=x,n_y=y+;
if (check(n_x,n_y))
{
dfs(n_x,n_y,time+);
vis[n_x][n_y]=;
} n_x=x+,n_y=y;
if (check(n_x,n_y))
{
dfs(n_x,n_y,time+);
vis[n_x][n_y]=;
} n_x=x,n_y=y-;
if (check(n_x,n_y))
{
dfs(n_x,n_y,time+);
vis[n_x][n_y]=;
} n_x=x-,n_y=y;
if (check(n_x,n_y))
{
dfs(n_x,n_y,time+);
vis[n_x][n_y]=;
}
} int main()
{
int i,j;
while (scanf("%d%d%d",&a,&b,&t)&&a+b+t)
{
getchar();
int wall=;
for (i=;i<=a;i++)
{
for (j=;j<=b;j++)
{
scanf("%c",&map[i][j]);
if (map[i][j]=='S')
{
s_x=i;
s_y=j;
}
if (map[i][j]=='D')
{
e_x=i;
e_y=j;
}
if (map[i][j]=='X')
wall++;
}
getchar();
} if (a*b-wall<=t)//所有路都走了还到不了终点,注意是 <=t ,可以少300ms
{
printf("NO\n");
continue;
} ok=;
memset(vis,,sizeof(vis));
int temp=t-(abs(s_x-e_x)+abs(s_y-e_y)); if (temp%==)//奇偶性相同才bfs
dfs(s_x,s_y,); if (ok)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
M - 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 ...
- 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的矩阵中,有一起点和终点,中间有墙,给出起点终点和墙,并给出步数,在该步数情况 ...
随机推荐
- CSAPP:异常控制流
在一般的情况下,处理器处理的指令序列是相邻的(顺序执行). 异常控制流提供了指令的跳转,它一部分是由硬件实现的,一部分是由操作系统实现的. 异常处理 在系统启动时,操作系统分配和初始化一张称为异常表的 ...
- mysql的innodb数据库引擎详解
http://www.jb51.net/softjc/158474.html 这篇文章主要介绍了mysql的innodb数据库引擎,需要的朋友可以参考下 一.mysql体系结构和存储引擎 1. ...
- Transact-SQL 参考(数据库引擎)
记录下这个地址: https://technet.microsoft.com/zh-cn/library/bb510741(v=sql.105).aspx
- 高仿快递100--实战之RadioGroup和RadioButton应用
1.RadioButton和CheckBox的差别: a.单个RadioButton在选中后,通过点击无法变为未选中 单个CheckBox在选中后.通过点击能够变为未选中 b.一组RadioButto ...
- pthread_create11121
#include <stdlib.h> #include <stdio.h> #include <pthread.h> void* test(void* args) ...
- Linux学习之inode说明
硬盘是常见的存储设备,最小单位叫做扇区,大小512kb. 文件存储在硬盘中,文件存储最小单位叫做块,大小通常为4k. iNode用于存放文件的元信息,元信息如下: 所有者 所有组 权限 时间戳,cti ...
- Unable to use slave's temporary directory /tmp - Can't create/write to file '/tmp/SQL_LOAD-' (Errcode: 17)
这个错误时在Mysql主从配置产生的,最后找到这个Mysql的一个bug http://bugs.mysql.com/bug.php?id=62055 bug的主要原因是:打开文件的函数中指定打开模式 ...
- Lucene.Net 介绍
1 lucene简介1.1 什么是lucenepowered by 25175.netLucene是一个全文搜索框架,而不是应用产品.因此它并不像www.baidu.com 或者google Desk ...
- hdu1018 Big Number 斯特林公式 求N!的位数。
Big Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- php 图片上传 文件上传 大小 限制
nginx 413 Request Entity Too Large Php无法上传文件 查看php脚本运行用户,写个php脚本 <?php echo shell_exec("id ...