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 ...
随机推荐
- gVim多标签页
我们一般使用的文本编辑器,如:editplus.ultraEdit等都是支持多标签页的,可以同时打开多个文件,方便切换,以前gVim只能打开多个窗口,或者一个窗口切出多个窗口来编辑,自从7.0以后Vi ...
- HTTP层 —— 中间件
1.简介 HTTP 中间件为过滤进入应用的 HTTP 请求提供了一套便利的机制.例如,Laravel 内置了一个中间件来验证用户是否经过授权,如果用户没有经过授权,中间件会将用户重定向到登录页面,否则 ...
- MySQL 테이블 타입(Heap, MyIsam, InnoDB...) 변경하기
alter table 을 이용해서 기존의 생성된 테이블의 타입(Heap, MyIsam, InnoDB...)을 변경하는 명령어 입니다. 잠시 까먹은 분은 계실지 몰라도 원래 모르는 ...
- JAXB - The JAXB Context
As we have seen, an object of the class JAXBContext must be constructed as a starting point for othe ...
- 关于ServletConfig的小结
在Servlet的配置文件中,可以使用一个或多个<init-param>标签为servlet配置一些初始化参数.当servlet配置了初始化参数后,web容器在创建servlet ...
- CS0016: 未能写入输出文件“c:\windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\data\34aae060\b7daa87d\App_Web_addadvice.aspx.cdcab7d2.ekhlcbjd.dll”--“目录名无效。 ”
产生原因: 应用程序运行时产生的临时文件需要存放到c:"windows"temp 文件夹下 而运行基于microsoft .net framework 框架下的应用程序 需要对te ...
- cocos2d-x实战 C++卷 学习笔记--第4章 win32平台下中文乱码问题
前言: 将GBK编码的字符串转为UTF-8编码.(通俗点说就是解决中文乱码问题) 简要介绍: 在Win32平台下通过 log 输出中文字符时,会出现中文乱码问题.同样的代码在 ios 和 Androi ...
- 第二十七篇、使用MVVM布局页面
思路:架构的设计模式主要有这么两种 >MVC :这种方式用得很多,也很是常见,不在过多的介绍 >MVVM:使用这种 常常需要导入第三方框架,常见的是响应式框架 >主要讲一下ViewM ...
- 第一篇、CSS3_transtion的使用
<html> <head> <title>这是一个CSS3的特性</title> <style> #box{ width: 150px; h ...
- 通过google找网站后台的方法
转自:http://cyuyanbiancheng.blog.hexun.com/69239903_d.html site:url.com '查看这个站点上的信息最好不加www,可以查看到不少的二级域 ...