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 ...
随机推荐
- Page Object 设计模式介绍
Page Object 是 Selenium 自动化测试项目开发实践的最佳设计模式之一,Page Object 的主要体现于对界面交互细节的封装,这样可以使测试案例更关注与业务而非界面细节,提高测试案 ...
- CSS层叠样式表的解释
css: 在标签上设置style属性css注释: /*z注释内容*/css样式的编写位置: 1.在标签的的style属性里 2.在head里面,style标签中写样式 ...
- Prim求MST最小生成树
最小生成树即在一个图中用最小权值的边将所有点连接起来.prim算法求MST其实它的主要思路和dijkstra的松弛操作十分相似 prim算法思想:在图中随便找一个点开始这里我们假定起点为“1”,以点1 ...
- [整理]修改git 默认编辑器为vim
git config --global core.editor vim
- 给Python初学者的一些编程建议
Python是一种非常富有表现力的语言.它为我们提供了一个庞大的标准库和许多内置模块,帮助我们快速完成工作.然而,许多人可能会迷失在它提供的功能中,不能充分利用标准库,过度重视单行脚本,以及误解Pyt ...
- lintcode-52-下一个排列
52-下一个排列 给定一个整数数组来表示排列,找出其之后的一个排列. 注意事项 排列中可能包含重复的整数 样例 给出排列[1,3,2,3],其下一个排列是[1,3,3,2] 给出排列[4,3,2,1] ...
- sql语句编写 有时候一个子查询可以拆分成多个子查询
sql语句编写 有时候一个子查询可以拆分成多个子查询
- [CF1041E]Tree Reconstruction
题目大意:有一棵树,现在给你每条树边被去掉时,形成的两个联通块中点的最大的编号分别是多少,问满足条件的树存不存在,存在输出方案 题解:一条边的两个编号中较大的一个一定是$n$,否则无解. 开始构造这棵 ...
- [洛谷P2197]nim游戏
题目大意:Nim游戏.地上有n堆石子,每人每次可从任意一堆石子里取出任意多石子,不能不取,且每次只能从一堆里取.没石子可取的人输.问是否存在先手必胜的策略. 题解:Nim游戏有一个定理,就是当所有棋子 ...
- [Leetcode] Remove duplicates from sorted array 从已排序的数组中删除重复元素
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...