狗要出门,且正好在T秒

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

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. using namespace std;
  6. typedef long long ll;
  7. const int step[][2] = {0,1,0,-1,1,0,-1,0};
  8. const int maxn = 10 + 7;
  9.  
  10. char Map[maxn][maxn];
  11. int m,n,t;
  12. int aimx,aimy;
  13. int bex,bey;
  14.  
  15. bool DFS(int x,int y,int tt)
  16. {
  17. if(x == 0 || x == m+1 || y == 0 || y == n+1) return false;
  18. if(x == aimx && y == aimy && tt == t) return true;
  19. int Dis = ((t - tt) - abs(x-aimx) - abs(y -aimy));
  20. if(Dis % 2 || Dis < 0) return false;
  21. for(int i = 0; i <4; ++i)
  22. {
  23. if(Map[x+step[i][0]][y+step[i][1]] != 'X')
  24. {
  25. Map[x+step[i][0]][y+step[i][1]] = 'X';
  26. //cout << " X : " << x << " Y : " << y << endl;
  27. if(DFS(x+step[i][0], y+step[i][1], tt+1)) return true;
  28. Map[x+step[i][0]][y+step[i][1]] = '.';
  29. }
  30. }
  31. return false;
  32. }
  33.  
  34. int main()
  35. {
  36. while(cin >> m >> n >> t && (n + m + t))
  37. {
  38. for(int i = 0; i < maxn; ++i)
  39. for(int j = 0; j < maxn; ++j) Map[i][j] = 'X';
  40. int cnt = 0;
  41. for(int i = 1; i <= m; ++i)
  42. {
  43. scanf("%s",Map[i] + 1);
  44. for(int j = 1; j <= n; ++j) if(Map[i][j] == 'S') bex = i, bey = j;
  45. else if(Map[i][j] == 'D') aimx = i, aimy = j;
  46. else if(Map[i][j] == 'X') cnt++;
  47. }
  48. if(m*n - cnt < t) {
  49. printf("NO\n");
  50. continue;
  51. }
  52. Map[bex][bey] = 'X';
  53. if(DFS(bex,bey,0)) {
  54. printf("YES\n");
  55. } else printf("NO\n");
  56. }
  57. return 0;
  58. }

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. 外部程序调用Django模块的解决办法

    Question django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not ...

  2. vue 移动端日期选择组件 vue-mobile-calendar

    vue-mobile-calendar cnpm install vue-mobile-calendar -S import Vue from 'vue' import Calendar from ' ...

  3. SQL Server进阶(三)单表查询

    示例数据库 点我下载 一条完整的sql语句 select top | distinct 字段, 表达式, 函数, ... from 表表达式 where 筛选条件 group by 分组条件 havi ...

  4. C#调用C++导出类的一个实例

    一直认为带导出类dll的只有VC自己可以调用,其它编程语言无法调用,今天看到一篇文章才知道自己错了.https://blog.csdn.net/huiyouyongdeyu2011/article/d ...

  5. 安装Rational Rose后提示java.lang.ClassNotFoundException

    1. 在运行中输入regedit回车,打开注册表编辑器2. 搜索 TrustedClasspath [REG_SZ] ,因为64位和32位不一样. 4.添加值c:\windows\java\trust ...

  6. Reshaper安装后vs快捷键不起作用

    做如上设置

  7. 【二】JConsole、VisualVM

    监控工具 jconsole.exe 只有10几k,真正的代码是包装在tools.jar中. 双击[本地线程]:sun.tools.jconsole.JConsole: 内存的线在上下起伏,证明是[垃圾 ...

  8. 在线xss练习平台

    在线xss练习平台 HTTPS://ALF.NU/ALERT1 这个是只要能输出alert1就算赢. No.1第一个就很简单了,什么都没有过滤,只需要闭合前面的标签就可以执行xss了. 1 " ...

  9. python中的*和**的用途

    def function_with_one_star(*t):    print(t, type(t)) def function_with_two_stars(**d)    print(d, ty ...

  10. artTemplate/template.js模板将时间戳格式化为正常的日期

    1:引用<script type="text/javascript" src="../js/artTemplate/template.js">< ...