ZOJ 2110 DFS
狗要出门,且正好在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的更多相关文章
- 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 ...
- DFS Zoj 2110
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2110 //2110 #include<stdio.h> #in ...
- ZOJ 2110 Tempter of the Bone(DFS)
点我看题目 题意 : 一个N×M的迷宫,D是门的位置,门会在第T秒开启,而开启时间小于1秒,问能否在T秒的时候到达门的位置,如果能输出YES,否则NO. 思路 :DFS一下就可以,不过要注意下一终止条 ...
- ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)
题意 一仅仅狗要逃离迷宫 能够往上下左右4个方向走 每走一步耗时1s 每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次 问狗是否有可能逃离这个迷宫 直接DFS 直道找到满足条件的路径 ...
- 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 ...
- zoj 2110 很好的dfs+奇偶剪枝
//我刚开始竟然用bfs做,不断的wa,bfs是用来求最短路的而这道题是求固定时间的 //剪纸奇偶剪枝加dfs #include<stdio.h> #include<queue> ...
- 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 ...
- POJ 1562 Oil Deposits (HDU 1241 ZOJ 1562) DFS
现在,又可以和她没心没肺的开着玩笑,感觉真好. 思念,是一种后知后觉的痛. 她说,今后做好朋友吧,说这句话的时候都没感觉.. 我想我该恨我自己,肆无忌惮的把她带进我的梦,当成了梦的主角. 梦醒之后总是 ...
- 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 ...
随机推荐
- 外部程序调用Django模块的解决办法
Question django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not ...
- vue 移动端日期选择组件 vue-mobile-calendar
vue-mobile-calendar cnpm install vue-mobile-calendar -S import Vue from 'vue' import Calendar from ' ...
- SQL Server进阶(三)单表查询
示例数据库 点我下载 一条完整的sql语句 select top | distinct 字段, 表达式, 函数, ... from 表表达式 where 筛选条件 group by 分组条件 havi ...
- C#调用C++导出类的一个实例
一直认为带导出类dll的只有VC自己可以调用,其它编程语言无法调用,今天看到一篇文章才知道自己错了.https://blog.csdn.net/huiyouyongdeyu2011/article/d ...
- 安装Rational Rose后提示java.lang.ClassNotFoundException
1. 在运行中输入regedit回车,打开注册表编辑器2. 搜索 TrustedClasspath [REG_SZ] ,因为64位和32位不一样. 4.添加值c:\windows\java\trust ...
- Reshaper安装后vs快捷键不起作用
做如上设置
- 【二】JConsole、VisualVM
监控工具 jconsole.exe 只有10几k,真正的代码是包装在tools.jar中. 双击[本地线程]:sun.tools.jconsole.JConsole: 内存的线在上下起伏,证明是[垃圾 ...
- 在线xss练习平台
在线xss练习平台 HTTPS://ALF.NU/ALERT1 这个是只要能输出alert1就算赢. No.1第一个就很简单了,什么都没有过滤,只需要闭合前面的标签就可以执行xss了. 1 " ...
- python中的*和**的用途
def function_with_one_star(*t): print(t, type(t)) def function_with_two_stars(**d) print(d, ty ...
- artTemplate/template.js模板将时间戳格式化为正常的日期
1:引用<script type="text/javascript" src="../js/artTemplate/template.js">< ...