HDU1010(dfs+剪枝)
Tempter of the Bone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 92693 Accepted Submission(s): 25191
The maze was a rectangle with sizes N by M. There was a door in the maze. At the beginning, the door was closed and it would open at the T-th second for a short period of time (less than 1 second). Therefore the doggie had to arrive at the door on exactly the T-th second. In every second, he could move one block to one of the upper, lower, left and right neighboring blocks. Once he entered a block, the ground of this block would start to sink and disappear in the next second. He could not stay at one block for more than one second, nor could he move into a visited block. Can the poor doggie survive? Please help him.
'X': a block of wall, which the doggie cannot enter;
'S': the start point of the doggie;
'D': the Door; or
'.': an empty block.
The input is terminated with three 0's. This test case is not to be processed.
/*
ID: LinKArftc
PROG: 1010.cpp
LANG: C++
*/ #include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define eps 1e-8
#define randin srand((unsigned int)time(NULL))
#define input freopen("input.txt","r",stdin)
#define debug(s) cout << "s = " << s << endl;
#define outstars cout << "*************" << endl;
const double PI = acos(-1.0);
const double e = exp(1.0);
const int inf = 0x3f3f3f3f;
const int INF = 0x7fffffff;
typedef long long ll; const int maxn = ;
int n, m, t;
char mp[maxn][maxn];
bool vis[maxn][maxn]; struct Node {
int x, y, step;
Node() {}
Node(int _x, int _y, int _s) : x(_x), y(_y), step(_s) {}
} start, door; int dx[] = { -, , , };
int dy[] = { , , , - }; bool dfs(Node cur) {
if (cur.step == t) {
if (mp[cur.x][cur.y] == 'D') return true;
return false;
}
int tmp = abs(cur.x - door.x) + abs(cur.y - door.y);
if ((tmp % ) != ((t - cur.step) % )) return false;
for (int i = ; i < ; i ++) {
int xx = cur.x + dx[i];
int yy = cur.y + dy[i];
if (mp[xx][yy] == 'X' || vis[xx][yy]) continue;
if (mp[xx][yy] == 'D' && (cur.step + != t)) continue;
vis[xx][yy] = true;
if (dfs(Node(xx, yy, cur.step + ))) return true;
else vis[xx][yy] = false;
}
return false;
} int main() {
//input;
while (~scanf("%d %d %d", &n, &m, &t)) {
if (n == && m == && t == ) break;
memset(mp, 'X', sizeof(mp));
memset(vis, , sizeof(vis));
int cnt = ;
for (int i = ; i <= n; i ++) {
for (int j = ; j <= m; j ++) {
scanf(" %c", &mp[i][j]);
if (mp[i][j] != 'X') cnt ++;
if (mp[i][j] == 'S') {
start = Node(i, j, );
vis[i][j] = true;
} else if (mp[i][j] == 'D') door = Node(i, j, t);
}
}
if (t > cnt - ) {
printf("NO\n");
continue;
}
if (dfs(start)) printf("YES\n");
else printf("NO\n");
} return ;
}
HDU1010(dfs+剪枝)的更多相关文章
- HDU1010 DFS+剪枝
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdu-1010 dfs+剪枝
思路: 剪枝的思路参考博客:http://www.cnblogs.com/zibuyu/archive/2012/08/17/2644396.html 在其基础之上有所改进 题意可以给抽象成给出一个 ...
- *HDU1455 DFS剪枝
Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- POJ 3009 DFS+剪枝
POJ3009 DFS+剪枝 原题: Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16280 Acce ...
- poj 1724:ROADS(DFS + 剪枝)
ROADS Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10777 Accepted: 3961 Descriptio ...
- DFS(剪枝) POJ 1011 Sticks
题目传送门 /* 题意:若干小木棍,是由多条相同长度的长木棍分割而成,问最小的原来长木棍的长度: DFS剪枝:剪枝搜索的好题!TLE好几次,终于剪枝完全! 剪枝主要在4和5:4 相同长度的木棍不再搜索 ...
- DFS+剪枝 HDOJ 5323 Solve this interesting problem
题目传送门 /* 题意:告诉一个区间[L,R],问根节点的n是多少 DFS+剪枝:父亲节点有四种情况:[l, r + len],[l, r + len - 1],[l - len, r],[l - l ...
- HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)
Counting Cliques Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))
Equation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- LA 6476 Outpost Navigation (DFS+剪枝)
题目链接 Solution DFS+剪枝 对于一个走过点k,如果有必要再走一次,那么一定是走过k后在k点的最大弹药数增加了.否则一定没有必要再走. 记录经过每个点的最大弹药数,对dfs进行剪枝. #i ...
随机推荐
- Qt 在控件上面绘图 label,pushbutton。。。。。
最近有点时间,就研究研究Qt ,提升一下自己 我记得我在刚开始学习Qt 的时候,想要在一个控件上面绘制图形,那就要构建一个新类来调用该控件的绘图函数 今天看到了狗哥的学习博客,感觉自己好渺小啊,按照狗 ...
- jmeter4.0☞如何汉化(二)
如何汉化jmeter打开jmeter,选择options_choose language_Chinese(simplified),如下图: 刚刚下载使用jmeter4.0的时候有点懵圈,英语实在是差劲 ...
- TensorFlow 同时调用多个预训练好的模型
在某些任务中,我们需要针对不同的情况训练多个不同的神经网络模型,这时候,在测试阶段,我们就需要调用多个预训练好的模型分别来进行预测. 调用单个预训练好的模型请点击此处 弄明白了如何调用单个模型,其实调 ...
- truffle自动化测试脚本
truffle自动化测试脚本 补充一个unbox 1.部署本地ganache环境 配置文件地址为本地地址 localhost:XXXX 上线的环境为 infura的url 2.命令: truffle ...
- lintcode-91-最小调整代价
91-最小调整代价 给一个整数数组,调整每个数的大小,使得相邻的两个数的差不大于一个给定的整数target,调整每个数的代价为调整前后的差的绝对值,求调整代价之和最小是多少. 注意事项 你可以假设数组 ...
- maven中进行go的编译
maven提供的插件maven-antrun-plugin真是个好东东,使得maven可以利用ant的很多功能. 最近需要实现在maven中实现对go代码的编译,添加如下代码在pom文件中即可. &l ...
- 【bzoj3033】太鼓达人 DFS欧拉图
题目描述 给出一个整数K,求一个最大的M,使得存在一个每个位置都是0或1的圈,圈上所有连续K位构成的二进制数两两不同.输出最大的M以及这种情况下字典序最小的方案. 输入 一个整数K. 输出 一个整数M ...
- 2017 Multi-University Training Contest - Team 3 RXD and functions(NTT)
题解: 我是参考的 http://blog.csdn.net/qq_32570675/article/details/76571666 这一篇 orz 原来可以这么变换,涨姿势 代码: #includ ...
- 2017 Multi-University Training Contest - Team 2 Puzzle
题目大意: 给定n, m, p.然后按照一个规则往n*m的方格里填数,最后一个方格是空格,然后玩拼图游戏,问能否复原 规则是:把1~n*m-1的排列中的第1,p+1,2*p+1.....个数依次取出来 ...
- oracle 导入导出语句
imp USERID/PSD@SID file='D:\1.dmp' full=y statistics=none exp USERID/PSD@SID file='D:\1.dmp' tables= ...