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 ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried desperately to get out of this maze.
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
The input consists of multiple test cases. The first line of each test case contains three integers N, M, and T (1 < N, M < 7; 0 < T < 50), which denote the sizes of the maze and the time at which the door will open, respectively. The next N lines give the maze layout, with each line containing M characters. A character is one of the following:
'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
For each test case, print in one line "YES" if the doggie can survive, or "NO" otherwise.
Sample Input
4 4 5
S.X.
..X.
..XD
....
3 4 5
S.X.
..X.
...D
0 0 0
Sample Output
NO
YES
Author: ZHANG, Zheng
Source: Zhejiang Provincial Programming Contest 2004
//C++ 20 172 姜伯约
/* 题意:
从S走向D,问能否恰好在第t个时刻走到 DFS:
比较经典的一道深搜,奇偶剪枝是比较亮的一点,亲可以自己手动画图
比较一下,会获益不少,其他和普通的dfs差不多。 */
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int n,m,t;
char g[][];
int mov[][]={,,,,,-,-,};
int flag,ex,ey;
void dfs(int x,int y,int cnt)
{
if(cnt>t || flag) return;
if(x==ex && y==ey && cnt==t) flag=;
int temp=(t-cnt)-abs(x-ex)-abs(y-ey);
if(temp< || (temp&))return; //奇偶剪枝
for(int i=;i<;i++){
int tx=x+mov[i][];
int ty=y+mov[i][];
if(tx>= && tx<n && ty>= && ty<m && g[tx][ty]!='X'){
g[tx][ty]='X';
dfs(tx,ty,cnt+);
g[tx][ty]='.';
}
}
}
int main(void)
{
while(scanf("%d%d%d",&n,&m,&t)!=EOF&&(n+m+t))
{
int x,y;
int cnt=;
for(int i=;i<n;i++){
scanf("%s",g[i]);
for(int j=;j<m;j++){
if(g[i][j]=='S')
x=i,y=j;
else if(g[i][j]=='.') cnt++;
else if(g[i][j]=='D') ex=i,ey=j;
}
}
if(cnt+<t){
puts("NO");continue;
}
flag=;
g[x][y]='X';
dfs(x,y,);
if(flag) puts("YES");
else puts("NO");
}
return ;
}
zoj 2110 Tempter of the Bone (dfs)的更多相关文章
- ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)
题意 一仅仅狗要逃离迷宫 能够往上下左右4个方向走 每走一步耗时1s 每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次 问狗是否有可能逃离这个迷宫 直接DFS 直道找到满足条件的路径 ...
- 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 ...
- ZOJ 2110 Tempter of the Bone(DFS)
点我看题目 题意 : 一个N×M的迷宫,D是门的位置,门会在第T秒开启,而开启时间小于1秒,问能否在T秒的时候到达门的位置,如果能输出YES,否则NO. 思路 :DFS一下就可以,不过要注意下一终止条 ...
- HDU1010:Tempter of the Bone(dfs+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 //题目链接 http://ycool.com/post/ymsvd2s//一个很好理解剪枝思想的博客 ...
- HDU 1010 Tempter of the Bone --- DFS
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- 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 ...
- HDOJ.1010 Tempter of the Bone (DFS)
Tempter of the Bone [从零开始DFS(1)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tem ...
- M - Tempter of the Bone(DFS,奇偶剪枝)
M - Tempter of the Bone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
随机推荐
- Oracle 使用Nid 修改数据库的DBID 和 Database Name
How to Change the DBID, DBNAME Using NID Utility (Doc ID 863800.1) Changing the DBID and Database Na ...
- centos6 下查看SELinux状态 关闭SELinux
转载自:https://blog.csdn.net/boomjane_testingblog/article/details/52859977 SELinux(Security-Enhanced Li ...
- uplift model学习笔记
一.解决的问题: 通常的 Propensity Model 和 Response Model 只是给目标用户打了个分,并没有确保模型的结果可以使得活动的提升最大化:它没有告诉市场营销人员,哪个用户最有 ...
- Webpack + Vue 多页面项目升级 Webpack 4 以及打包优化
0. 前言 早在 2016 年我就发布过一篇关于在多页面下使用 Webpack + Vue 的配置的文章,当时也是我在做自己一个个人项目时遇到的配置问题,想到别人也可能遇到跟我同样的问题,就把配置的思 ...
- ethereum(以太坊)(五)--Bool
pragma solidity ^0.4.0; contract Bool{ uint num1 = 100; uint num2 = 200; bool _c = true; // &&am ...
- php 操作 mysql 实现批量执行mysql语句 mysql文件
<?php /** * 批量运行sql文件 * 正则分隔是重点 preg_split("/;[\r\n]+/", filecontent) */ $config = requ ...
- The Road to learn React书籍学习笔记(第一章)
react灵活的生态圈 Small Application Boilerplate: create-react-app Utility: JavaScript ES6 and beyond Styli ...
- svn git 导入本地文件到远程服务器 import
以前,想要把本地的一个文件上传到svn 或者git 服务器的时候,都要先把服务器上的文件夹down 下来,然后把要添加的文件添加进去,然后提交. 想想都麻烦. 现在我们用import 命令就可以做到, ...
- Pascal 杨辉三角
用于打印杨辉三角的程序,有多种算法仅提供一种 PRogram yh (input,ouput);var m,n,c:integer;Begin For m:=0 TO 10 Do Begin ...
- USACO Section1.3 Wormholes 解题报告
wormhole解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------- ...