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 ...
随机推荐
- JAVA中局部变量 和 成员变量有哪些区别
JAVA中局部变量 和 成员变量有哪些区别 1.定义的位置不一样<重点>***局部变量:在方法的内部成员变量:在方法的外部,直接写在类当中 2.作用范围不一样<重点>***局部 ...
- Groovy 设计模式 -- Strategy 模式
策略模式 https://en.wikipedia.org/wiki/Strategy_pattern In computer programming, the strategy pattern (a ...
- Linux文件权限设置
基本概念 https://linux.cn/article-7418-1.html#3_8880 用户管理 文件权限设置 -添加用户账户08% -理解 /etc/passwd 中的内容12% -理解 ...
- vim 配置一:
一.vim前期准备 安装vimsudo apt-get install vim 需要保证自己的 vim 配置在 7.4 以上,有些插件只支持 7.4 以上的 vim 在根目录下建立 .vimrc 文件 ...
- flex中使用white-space
在微信小程序开发中,view设置为flex布局,但是flex的flex-wrap属性不起作用,如果起作用的话,默认值即no-wrap不换行.如果要测试view-scroll并且scroll-x 就没法 ...
- luogu P4099 [HEOI2013]SAO
传送门 吐槽题目标题 这个依赖关系是个树,可以考虑树型dp,设f_i表示子树i的答案 因为这是个序列问题,是要考虑某个数的位置的,所以设\(f_{i,j}\)表示子树i构成的序列,i在第j个位置的方案 ...
- Utterance-Wise Recurrent Dropout And Iterative Speaker Adaptation For Robust Monaural Speech Recognition
单声道语音识别的逐句循环Dropout迭代说话人自适应 WRBN(wide residual BLSTM network,宽残差双向长短时记忆网络) [2] J. Heymann, L. Dr ...
- 转载-HashMap1.7源码分析
原文地址-https://www.cnblogs.com/chengxiao/p/6059914.html HashMap实现原理及源码分析 哈希表(hash table)也叫散列表,是一种非常重 ...
- Flume配置Failover Sink Processor
1 官网内容 2 看一张图一目了然 3 详细配置 source配置文件 #配置文件: a1.sources= r1 a1.sinks= k1 k2 a1.channels= c1 #负载平衡 a1.s ...
- jq的dom操作
代码可以在该网址测试:www.w3school.com.cn/tiy/t.asp?f=jquery_manipulation_detach_move attr 使用函数来设置属性/值:函数参数为选择器 ...