狗要出门,且正好在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. Vector集合

    Vector集合也是List接口的一个实现类,但是它是同步的,这就意味着是单线程的,速度比较慢,被ArrayList集合所取代了(PS:为什么我现在也还不知道,先记录了)

  2. Silverlight用户无法注册之MySql.Data.dll不一致

    本篇博文记录本人解决一个"用户无法注册"的问题的过程 1 问题描述: 用户可以删除:但不能注册,也不能修改权限: 图 1用户注册失败 图 2修改用户权限出错 2 解决过程 1)粗暴 ...

  3. SQL Server进阶(十二)常用函数

    在SQL 2012基础教程中列出子句是按照以下顺序进行逻辑处理. FROM WHERE GROUP BY HAVING SELECT ORDER BY FROM TableName WHERE Use ...

  4. 4.mysql(slow_log/generic_log/audit)

    一.慢查询日志进阶 <1>相关参数 1.slow_query_log #是否开启慢查询日志 2.slow_query_log_file #慢查询日志文件名,在my.cnf我们已经定义为sl ...

  5. MySQL Out-of-Band 攻击

    概述 当涉及到MSSQL与Oracle时,Out-of-Band 注入是非常好的方式.但我注意到MySQL注入的情况并非如此,于是我准备以自己在SQL注入方面的经验做相关的研究.我们可以利用诸如loa ...

  6. vue 中跨组件的表单验证

    使用的是element写的,里面提供了表单验证. 子组件是这样的 <template> <div> <el-form :model="value" r ...

  7. 模拟用户登录(获取cookie/实例化session)

    第一种方法:通过本地浏览器保存的cookie进行登陆 url1 = 'https://passport.cnblogs.com/user/signin?ReturnUrl=https%3A%2F%2F ...

  8. CPU缓存一致性协议—MESI详解

    MESI(也称伊利诺斯协议)是一种广泛使用的支持写回策略的缓存一致性协议,该协议被应用在Intel奔腾系列的CPU中. MESI协议中的状态 CPU中每个缓存行使用的4种状态进行标记(使用额外的两位b ...

  9. maven的pom.xml文件的标签详解

    该博文引至:https://www.cnblogs.com/hafiz/p/5360195.html <project xmlns="http://maven.apache.org/P ...

  10. Mybatis--课程中循序渐进的体会 《黑马程序员_Springmvc+Mybatis由浅入深全套视频教程video》

    mybatis 刚开始是用最原始的方法开发了一个入门程序,(没有dao) 1.将数据源配置在SqlMapConfig.xml 2.写一个po类 和映射文件User.xml(中的namespace=“名 ...