HDOJ1010 (DFS+奇偶剪枝)
Tempter of the Bone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 107043 Accepted Submission(s): 29107
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.
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
const int MAXN=;
int n,m,T;
char mz[MAXN][MAXN];
int vis[MAXN][MAXN];
int sy,sx,gy,gx;
int dy[]={,,,-};
int dx[]={,,-,};
bool dfs(int y,int x,int step)
{
if(y==gy&&x==gx&&step==T)
{
return true;
}
int rem=T-step;
int need=abs(y-gy)+abs(x-gx);
if(rem<need||(rem-need)%!=)//奇偶剪枝:迂回,若能到达终点,那么至少所需的步数与还剩余的步数奇偶性相同
{
return false;
}
for(int i=;i<;i++)
{
int ny=y+dy[i];
int nx=x+dx[i];
if(<=ny&&ny<n&&<=nx&&nx<m&&mz[ny][nx]!='X')
{
if(!vis[ny][nx])
{
vis[ny][nx]=;
if(dfs(ny,nx,step+))
{
return true;
}
vis[ny][nx]=;
}
}
}
return false;
}
int main()
{
while(cin>>n>>m>>T&&(n+m+T)!=)
{
memset(vis,,sizeof(vis));
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
cin>>mz[i][j];
if(mz[i][j]=='S')
{
sy=i;
sx=j;
}
else if(mz[i][j]=='D')
{
gy=i;
gx=j;
}
}
}
vis[sy][sx]=;
if(dfs(sy,sx,))
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
return ;
}
HDOJ1010 (DFS+奇偶剪枝)的更多相关文章
- hdoj--1010<dfs+奇偶剪枝>
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目描述:在n*m的矩阵中,有一起点和终点,中间有墙,给出起点终点和墙,并给出步数,在该步数情况 ...
- 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+奇偶剪枝)
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 + 奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 杭电1010(dfs + 奇偶剪枝)
题目: The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked ...
- 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+奇偶剪枝+回溯)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdu1010Tempter of the Bone(dfs+奇偶剪枝)
题目链接:pid=1010">点击打开链接 题目描写叙述:给定一个迷宫,给一个起点和一个终点.问是否能恰好经过T步到达终点?每一个格子不能反复走 解题思路:dfs+剪枝 剪枝1:奇偶剪 ...
随机推荐
- Hadoop的Docker镜像构建
1.Dockerfile ###Dockerfile -- beagin FROM ubuntu:trusty #MAINTAINER The Hue Team "https://githu ...
- PHP 学习(一)——课程介绍
一.课程路线介绍 教程的学习路线按照:初级——>中级——>高级——>项目实做 初级: 中级: 高级: 项目实做: 整体: Php体系了解:
- vue中编辑代码是不注意格式时会报错
1.是因为我们使用了eslint的代码规范,我们不要使用这种规范就好 2.在build目录下找到webpack.base.conf.js 在里面找到关于eslint的相关配置注释或移除掉就好
- Spring初学之使用外部配置文件dataSource
一.在Spring的基础上还要另外导入c3p0包和mysql的驱动包. 二.配置文件, jdbc.propertices:这里只做了一些简单配置 user=root password=123 driv ...
- java八大基本类型介绍
//今天说一下java的八大基本类型: // 数字类型:byte(8位).short(16位).int(32位).long(64位) //浮点类型:float(32位).double(64位) //字 ...
- 第一个Python程序hello.py提示出现File "<stdin>",line 1错误
写第一个Python程序hello.py,内容仅有一句,print 'hello world', 运行 Python hello.py 出错,提示: File "<stdin>& ...
- dede数据库表结构和dedecms数据库字段说明
表名:dede_addonarticle (ENGINE=MyISAM/CHARSET=gbk) 说明:Top 字段名 说明描述 具体参数 aid 文章ID mediumint(8) unsigned ...
- CentOS下用于查看系统当前登录用户信息的4种方法
作为系统管理员,你可能经常会(在某个时候)需要查看系统中有哪些用户正在活动.有些时候,你甚至需要知道他(她)们正在做什么.本文为我们总结了4种查看系统用户信息(通过编号(ID))的方法. 1. 使用w ...
- 运行php的时候出现计算机中丢失 MSVCR110.dll怎么解决
运行php的时候出现计算机中丢失 MSVCR110.dll怎么解决 一.总结 一句话总结:因为现在php所有的 5.5 环境都是基于 vc11 的编译脚本下生成的,所以在 windows 下你得安装相 ...
- Jedis的八种调用方式(功能:事务,管道)
1. packagecom.irwin.redis; 2. 3. importjava.util.Arrays; 4. importjava.util.List; ...