狗要出门,且正好在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. Ubuntu Server Download

    点击查看所有版本(中国站点) http://mirror.lzu.edu.cn/ubuntu-releases/

  2. SpringBoot 2.0集成spring-data-elasticsearch

    1 资料 https://segmentfault.com/a/1190000015568618 https://github.com/JeffLi1993/springboot-learning-e ...

  3. html取消回车刷新提交

    <form class="weui-search-bar__form" onsubmit="return false;"> <form cla ...

  4. ****** 五十 ******、软设笔记【UML分析和意义】-类图、对象图、状态图、活动图、顺序图、协作图、构件图、部署图,动静态模式

    一.类图(Class Diagram) 描述一组类.接口.协作已经它们之间的图,用来显示系统中各个类的静态结构图. 类之间的关系(relationship) *依赖(dependency) *泛化(g ...

  5. Javaweb学习笔记——(九)——————Servlet的进入,及ServletConfig、GenericServlet、HttpServlet、ServletContext、获取类路径资源

    Servlet1.什么是Servlet? *Servlet是Javaweb三大组件之一(Servlet,Filter,Listener) *Servlet是用来处理客户端请求的动态资源 *Servle ...

  6. 如何使用xss带cookie

    参考连接:https://pentesterlab.com/exercises/xss_and_mysql_file/course 打开测试网站: 然后在192.168.1.46机器上使用socat, ...

  7. html5 area实例

    真实页面效果:就是一张图 html代码: <!DOCTYPE HTML> <html> <style> body{ padding:0px; margin:0px; ...

  8. Caused by: java.lang.InstantiationException: cn.at.bean.domain.ConstantInt

      org.springframework.jdbc.UncategorizedSQLException: ConnectionCallback; uncategorized SQLException ...

  9. jQuery.rotate.js笔记

    1. jQuery.rotate.js是什么 一个开源的兼容多浏览器的jQuery插件用来对元素进行任意角度的旋转动画. 这个库开发的目的是为了旋转img的,在3.x之后的版本可能支持其它元素,但旋转 ...

  10. 配置虚拟机 Linux 静态IP

    一.查看IP.子网掩码.网关 虚拟网络编辑器 NAT中获取 取消勾选DHCP 二.查看DNS 虚拟机DNS与Windows设置相同 三.配置linux [root@lhs800 ~]# vi /etc ...