ZOJ 2110 Tempter of the Bone(DFS)
题意 : 一个N×M的迷宫,D是门的位置,门会在第T秒开启,而开启时间小于1秒,问能否在T秒的时候到达门的位置,如果能输出YES,否则NO。
思路 :DFS一下就可以,不过要注意下一终止条件再判断一下时间,还有因为题目中要求走过的路要变成墙,所以每次走的时候要注意一下把路变成墙,但是如果你不走这条路了,要记得变回来。还有这个题必须剪枝,否则超时超到疯啊,DFS函数中那个剪枝不怎么好想,T-t代表的是在当前位置还需要T-t步路。而fabs(ex-x)+fabs(ey-y)指的是当前位置离终点最短还有着些步数,如果两者之差不小于0的话,T-t应该等于fabs(ex-x)+fabs(ey-y)+s,这个s,如果再扩展的话增加的长宽必定是偶数,所以奇数是不可达的
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string.h> using namespace std ; int N,M,T ;
char mapp[][] ;
int mp[][];
int sx,sy ;
int ex,ey ;
bool flag ;
int ans;
int dire[][] = {{,-},{,},{,},{-,}} ; void DFS(int x,int y,int t)
{
if(x == ex && y == ey&&t==T)
{
flag = true ;
return ;
}
int temp = (T-t)-fabs(ex-x)-fabs(ey-y) ;
if(temp < || temp%) return ;
for(int i = ; i < ; i++)
{
int xx = x+dire[i][] ;
int yy = y+dire[i][] ;
if(xx >= && xx < N && yy >= && yy < M && mp[xx][yy])
{
mp[xx][yy] = ;
DFS(xx,yy,t+) ;
if(flag) return ;
mp[xx][yy] = ;
}
}
}
int main()
{
while(scanf("%d %d %d",&N,&M,&T)!=EOF)
{
getchar();
if(N == && M == && T == ) break ;
memset(mp,,sizeof(mp)) ;
flag = false ;
int wall = ;
for(int i = ; i < N ; i++)
{
scanf("%s",mapp[i]);
for(int j = ; j < M ; j++)
{
if(mapp[i][j] == 'S')
sx = i ,sy = j ;
else if(mapp[i][j] == 'D')
{
ex = i,ey = j ;
mp[i][j] = ;
}
else if(mapp[i][j] == '.')
mp[i][j] = ;
else wall ++ ;
}
}
if(N*M-wall <= T)
{
printf("NO\n") ;
continue ;
}
mp[sx][sy] = ;
DFS(sx,sy,) ;
if(flag)
printf("YES\n") ;
else printf("NO\n") ;
}
return ;
}
ZOJ 2110 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 ...
- ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)
题意 一仅仅狗要逃离迷宫 能够往上下左右4个方向走 每走一步耗时1s 每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次 问狗是否有可能逃离这个迷宫 直接DFS 直道找到满足条件的路径 ...
- zoj 2110 Tempter of the Bone (dfs)
Tempter of the Bone Time Limit: 2 Seconds Memory Limit: 65536 KB The doggie found a bone in an ...
- ZOJ 2110 Tempter of the Bone
Tempter of the Bone Time Limit: 2 Seconds Memory Limit: 65536 KB The doggie found a bone in an ...
- 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 直接上中文了 Descriptions: 暑假的时候,小明和朋友去迷宫中寻宝.然而,当他拿到宝贝时,迷宫开始剧烈震动,他感到地面正在下沉,他们意识到这是一个陷阱 ...
- 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(DFS+剪枝) 2016-05-06 09:12 432人阅读 评论(0) 收藏
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 ...
随机推荐
- ADO和ADO.NET有什么不同?
1.一些ADO中常见的类型比如RecordSet在ADO.NET中已经没有了,而且在ADO.NET中也新增了许多在传统ADO中找不到的直接对应的新类型(如数据适配器): 2.传统的ADO主要针对紧密连 ...
- JDK Tools - xjc: 将 XML Schema 编译成 Java 类
xjc 是 JAXB 将 xsd 生成 Java 类的工具. 命令格式 xjc [ options ] schema file/URL/dir/jar ... [-b bindinfo ] ... 命 ...
- sharepoint 备份和还原site脚本
<个人积累,转载请注明出处> Backup-SPSite "http://www.abc.com/sites/TestWorkflowCenter" -path C:\ ...
- Acitivity间数据的传递
使用startActivityForResult方法进行数据传递. MainActivity.java: public class MainActivity extends Activity { ...
- CORS 跨域
跨域请求一直是网页编程中的一个难题,在过去,绝大多数人都倾向于使用JSONP来解决这一问题.不过现在,我们可以考虑一下W3C中一项新的特性——CORS(Cross-Origin Resource Sh ...
- Centos7最小化安装后(minimal)安装图形界面
centos7下载地址:http://mirrors.cqu.edu.cn/CentOS/7/isos/x86_64/CentOS-7-x86_64-Minimal-1511.iso 下载后用vmwa ...
- linux系统文件属性
1 硬链接概念 硬链接是指通过索引节点(Inode)来进行链接,在Linux(ext2,ext3)文件系统中,保存在磁盘分区中的文件不管是什么类型都会给它分配一个编号,这个编号被称为索引节点编号(I ...
- iOS开发——图片轮播图+单选选项
由于公司开发需要,需要滚动每道评测题, 并且一道评测题单项选择,按钮和文字都可点击选中 (单选比多选复杂一点,但是原理差不多) 1.当初任务紧,代码也没有优化,仅供思路参考,先放几张图 2.代码部分 ...
- Ubuntu 14.04 eclipse 提示框背景色更改
首先查看系统设置->外观->主题. 不同的主题需要更改的文件不同 sudo vim /usr/share/themes/主题(就是刚才主题的名字,ubuntu14.04默认是Ambianc ...
- 高并发编程陷阱之check and set
今天公司CTO跟隔壁部门开技术会,旁听了一下.所讲的内容感觉好高大上啊!简单记录一下 场景是这样的: if(check(id)===true) { }else{ set(id); } 什么意思呢? 就 ...