狗要出门,且正好在T秒

就是DFS + 剪枝, 联系一下剪枝技巧

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int step[][2] = {0,1,0,-1,1,0,-1,0};
const int maxn = 10 + 7; char Map[maxn][maxn];
int m,n,t;
int aimx,aimy;
int bex,bey; bool DFS(int x,int y,int tt)
{
if(x == 0 || x == m+1 || y == 0 || y == n+1) return false;
if(x == aimx && y == aimy && tt == t) return true;
int Dis = ((t - tt) - abs(x-aimx) - abs(y -aimy));
if(Dis % 2 || Dis < 0) return false;
for(int i = 0; i <4; ++i)
{
if(Map[x+step[i][0]][y+step[i][1]] != 'X')
{
Map[x+step[i][0]][y+step[i][1]] = 'X';
//cout << " X : " << x << " Y : " << y << endl;
if(DFS(x+step[i][0], y+step[i][1], tt+1)) return true;
Map[x+step[i][0]][y+step[i][1]] = '.';
}
}
return false;
} int main()
{
while(cin >> m >> n >> t && (n + m + t))
{
for(int i = 0; i < maxn; ++i)
for(int j = 0; j < maxn; ++j) Map[i][j] = 'X';
int cnt = 0;
for(int i = 1; i <= m; ++i)
{
scanf("%s",Map[i] + 1);
for(int j = 1; j <= n; ++j) if(Map[i][j] == 'S') bex = i, bey = j;
else if(Map[i][j] == 'D') aimx = i, aimy = j;
else if(Map[i][j] == 'X') cnt++;
}
if(m*n - cnt < t) {
printf("NO\n");
continue;
}
Map[bex][bey] = 'X';
if(DFS(bex,bey,0)) {
printf("YES\n");
} else printf("NO\n");
}
return 0;
}

ZOJ 2110 DFS的更多相关文章

  1. HDU 1010 Tempter of the Bone (ZOJ 2110) DFS+剪枝

    传送门: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1010 ZOJ:http://acm.zju.edu.cn/onlinejudge/showPr ...

  2. DFS Zoj 2110

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2110 //2110 #include<stdio.h> #in ...

  3. ZOJ 2110 Tempter of the Bone(DFS)

    点我看题目 题意 : 一个N×M的迷宫,D是门的位置,门会在第T秒开启,而开启时间小于1秒,问能否在T秒的时候到达门的位置,如果能输出YES,否则NO. 思路 :DFS一下就可以,不过要注意下一终止条 ...

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

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

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

  6. zoj 2110 很好的dfs+奇偶剪枝

    //我刚开始竟然用bfs做,不断的wa,bfs是用来求最短路的而这道题是求固定时间的 //剪纸奇偶剪枝加dfs #include<stdio.h> #include<queue> ...

  7. POJ 1979 Red and Black (zoj 2165) DFS

    传送门: poj:http://poj.org/problem?id=1979 zoj:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problem ...

  8. POJ 1562 Oil Deposits (HDU 1241 ZOJ 1562) DFS

    现在,又可以和她没心没肺的开着玩笑,感觉真好. 思念,是一种后知后觉的痛. 她说,今后做好朋友吧,说这句话的时候都没感觉.. 我想我该恨我自己,肆无忌惮的把她带进我的梦,当成了梦的主角. 梦醒之后总是 ...

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

随机推荐

  1. 复杂sql查询语句

    视图也叫虚表 1.表中保存实际数据,视图保存从表中取出数据所使用的SELECT语句,视图也是一张表,之间区别是是否保存实际数据. 2.使用视图可以完成跨多表查询数据.可以将常用SELECT语句做成视图 ...

  2. 绕不开的hadoop

    安装 jdk 1.8 # 官网下载可能比较慢,请自行搜索国内镜像源 wget http://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a ...

  3. JS 比较两个数组是否相等 是否拥有相同元素

    Javascript怎么比较两个数组是否相同?JS怎么比较两个数组是否有完全相同的元素?Javascript不能直接用==或者===来判断两个数组是否相等,无论是相等还是全等都不行,以下两行JS代码都 ...

  4. 新SQL temp

    select a.createtime, -- 日期 dept.name as deptName, -- 科室 (select t.docname from ( SELECT u.clinic_id ...

  5. 9.selenium

    1.安装与入门 pip3 install selenium 将chromedriver放到一个没有权限要求的目录 from selenium import webdriver driverpath=& ...

  6. Javaweb学习笔记——(十三)——————JSTL、JSTL核心标签库、自定义标签、有标签体的标签、带有属性的标签、MVC、Javaweb三层框架

    JSTLApache提供的标签库 jar包:jstl-1.2.jar,如果传MyEclipse,他会在我们导入jar包,无需自己导入,如果没有使用MyEclipse那么需要自行导入.--------- ...

  7. GCC编译器原理(一)03------GCC 工具:gprof、ld、libbfd、libiberty 和libopcodes

    1.3.7 gprof:性能分析工具 参考文档:https://www.cnblogs.com/andashu/p/6378000.html gprof是GNU profile工具,可以运行于linu ...

  8. Inline Route Constraints in ASP.NET Core MVC

    原文 ASP.NET MVC5和Web API2的一个新特性是attribute routing, 通过它我们可以使用[Route]来定义路由模板: public class MessagesCont ...

  9. 数据库设计理论与实践·<二>概念设计与逻辑设计

    2一.概念设计 1.1 概念设计关键知识 1.2 辨析 实体与属性的区别: ①实体能进一步用多个属性来描述,属性却不能,属性是不可再细分/分割的原子项. ②实体内部或者多个实体之间存在联系,而属性无. ...

  10. Python的集合和元组

    一.元组 元组也是一个list,但它的值不能改变 Python 的元组与列表类似,不同之处在于元组的元素不能修改. 元组使用小括号,列表使用方括号. 元组创建很简单,只需要在括号中添加元素,并使用逗号 ...