点我看题目

题意 : 一个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)的更多相关文章

  1. 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 ...

  2. ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)

    题意  一仅仅狗要逃离迷宫  能够往上下左右4个方向走  每走一步耗时1s  每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次  问狗是否有可能逃离这个迷宫 直接DFS  直道找到满足条件的路径 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 【HDU - 1010】Tempter of the Bone(dfs+剪枝)

    Tempter of the Bone 直接上中文了 Descriptions: 暑假的时候,小明和朋友去迷宫中寻宝.然而,当他拿到宝贝时,迷宫开始剧烈震动,他感到地面正在下沉,他们意识到这是一个陷阱 ...

  7. Tempter of the Bone(dfs+奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  8. 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 ...

  9. Tempter of the Bone(dfs+奇偶剪枝)题解

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

随机推荐

  1. LintCode 55 比较字符串

    比较两个字符串A和B,确定A中是否包含B中所有的字符.字符串A和B中的字符都是 大写字母 注意事项 在 A 中出现的 B 字符串里的字符不需要连续或者有序.   样例 给出 A = "ABC ...

  2. SharpDevelop 编译时,任务失败,因为未找到“resgen.exe”的解决方法

    在git clone sprite的项目,在本地编译的时候,会出现 任务失败,因为未找到“resgen.exe”,或未安装正确的 Microsoft Windows SDK.任务正在注册表项 HKEY ...

  3. SharePoint移动客户端--Rshare 中的Smart Cache

    Rshare中的Smart Cache 能好好的帮助那些移动客户,当网络信号不好或者没有wifi的时候,cache大有可为,只要你在上飞机执勤cache 了相关文档,你就可以在飞行模式下继续你的工作. ...

  4. 模仿微博 用OC语言编写

    演示如下 源代码下载:模仿微博.zip

  5. ajax发送请求

    首先创建XMLHttpRequest对象,利用此对象发送请求 主页面 <!doctype html> <html lang="en"> <head&g ...

  6. 理解hadoop的Map-Reduce数据流(data flow)

    http://blog.csdn.net/yclzh0522/article/details/6859778 Map-Reduce的处理过程主要涉及以下四个部分: 客户端Client:用于提交Map- ...

  7. ASP大数据量使用GetRows()提升速度

    抽取10万条数据,Access数据库,GetRows() 现有10W条数据,Access数据库保存 通过正常提取: <% Set conn= Server.CreateObject(" ...

  8. mac安装软件运行提示「xxx.app已损坏,打不开.你应该将它移到废纸篓」的解决办法

    「xxx.app已损坏,打不开.你应该将它移到废纸篓」,其实并非你安装的软件已损坏,而是Mac系统的安全设置问题,往往这些软件可能是经过了汉化或者破解,所以被Mac认为「已损坏」,那么解决方法就是临时 ...

  9. 在linux CentOS6上安装web环境

    感谢浏览,欢迎交流=.= 都说linux作为服务器优于window,近期也是学习了下linux. win7下安装了linux虚拟机,购买linux阿里云主机,开启linux之旅. 进入正题,在linu ...

  10. ICBC中的路由设置

    才去的中国工商银行,用身份证叫了A0076的号,前边还有26个人,闲来无聊果断拿出手机收取wifi.有两个ssid为ICBC的路由,信道分别是1号和6号,还好不需要密码,不过一会就连接上了. 那我先上 ...