狗要出门,且正好在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-数据库刷题

    因是个人总结,只列出对自己有用的或较难的: 下面这道题,第一次拿到,我尝试用 开窗函数 ROW_NUMBER()OVER() 编号,但是发现不能够处理好连续的问题, 上网查找了别人的解法记录下来,其实 ...

  2. springBoot整合多数据源

    springBoot整合相关 1:springBoot整合多数据源: 应用场景:     项目需要同时连接两个不同的数据库A, B,并且它们都为主从架构,一台写库,多台读库. 工具/版本: jdk1. ...

  3. 细说shiro之二:组件架构

    官网:https://shiro.apache.org/ Shiro主要组件包括:Subject,SecurityManager,Authenticator,Authorizer,SessionMan ...

  4. springboot(十八):解决跨域问题

    在controller上添加@CrossOrigin注解,如下: @RestController @RequestMapping("course") @CrossOrigin pu ...

  5. Image转Base64

    今天和一个朋友联调图片转Base64时发现一个问题 public static string ImageToBase64(Image img) { BinaryFormatter binFormatt ...

  6. C# 使用 log4net 记录日志

    Ø  前言 在一般的开发应用中,都会涉及到日志记录,用于排查错误 或 记录程序运行时的日志信息.log4net 库是 Apache log4j 框架在 Microsoft .NET 平台的实现,是一个 ...

  7. Hibernate主键生成策略及选择

    1 .increment:适用于short,int,long作为主键,不是使用数据库自动增长机制 这是hibernate中提供的一种增长机制 在程序运行时,先进行查询:select max(id) f ...

  8. pycharm中创建包时加入的_init_.py文件及_all_的作用

    init__.py的主要作用是: 1. Python中package的标识,不能删除 2. 定义__all__用来模糊导入 3. 编写Python代码(不建议在__init__中写python模块,可 ...

  9. [C++]PAT乙级1010. 一元多项式求导 (25/25)

    /* 1010. 一元多项式求导 (25) 设计函数求一元多项式的导数.(注:x^n(n为整数)的一阶导数为n*x^n-1.) 输入格式: 以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1 ...

  10. 目前比较火的前端框架及UI组件

    看到的一篇总结性的文章,收藏一下,感兴趣的可以自己看看,哪些是已经会的,哪些是没听说过的,哪些是一知半解的,都可以稍微看看. 一.前端框架库: 1.Zepto.js 地址:点击打开链接 描述:Zept ...