hdu1010 - dfs,奇偶剪枝
给一个迷宫,问从起点到终点存不存在一条长度为T的路径。
-----------------------------------------------------------------------------

判断(T-当前步数)的奇偶性 和 (终点-当前位置)距离的奇偶性是否相同。
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm> #define MAX(a,b) ((a)>=(b)?(a):(b))
#define MIN(a,b) ((a)<=(b)?(a):(b))
#define OO 0x0fffffff
typedef long long LL;
using namespace std;
const int N = ;
const int skip[][] = { { , }, { -, }, { , }, { , - } }; int m, n, t;
int sx, sy, ex, ey;
char maze[N][N];
bool vis[N][N];
bool judge(int x, int y){
if (x< || y< || x >= m || y >= n) return false;
if (vis[x][y]) return false;
if (maze[x][y] == 'X') return false;
return true;
} bool dfs(int x, int y, int step){
if (x == ex&&y == ey&&step == t) return true;
int tag = t - step - abs(ex-x) - abs(ey-y);
if(tag<||tag&) return false;
for (int i = ; i<; i++){
int tx = x + skip[i][];
int ty = y + skip[i][];
if (judge(tx, ty)){
vis[tx][ty] = true;
if (dfs(tx, ty, step + )) return true;
vis[tx][ty] = false;
}
}
return false;
} int main(){
while (scanf("%d%d%d", &m, &n, &t), m + n + t){
for (int i = ; i<m; i++) {
scanf("%s", maze[i]);
for (int j = ; j<n; j++){
if (maze[i][j] == 'D') sx = i, sy = j;
if (maze[i][j] == 'S') ex = i, ey = j;
}
}
memset(vis, false, sizeof(vis)); if (dfs(sx,sy,)) puts("YES");
else puts("NO");
}
return ;
}
hdu1010 - dfs,奇偶剪枝的更多相关文章
- hdoj--1010<dfs+奇偶剪枝>
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目描述:在n*m的矩阵中,有一起点和终点,中间有墙,给出起点终点和墙,并给出步数,在该步数情况 ...
- HDU1010 Tempter of the Bone【小狗是否能逃生----DFS奇偶剪枝(t时刻恰好到达)】
Tempter of the Bone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四 ...
- hdu.1010.Tempter of the Bone(dfs+奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdu 1010:Tempter of the Bone(DFS + 奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 杭电1010(dfs + 奇偶剪枝)
题目: The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked ...
- Tempter of the Bone(dfs奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- Tempter of the Bone(dfs+奇偶剪枝)题解
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- HDU 1010:Tempter of the Bone(DFS+奇偶剪枝+回溯)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdu1010Tempter of the Bone(dfs+奇偶剪枝)
题目链接:pid=1010">点击打开链接 题目描写叙述:给定一个迷宫,给一个起点和一个终点.问是否能恰好经过T步到达终点?每一个格子不能反复走 解题思路:dfs+剪枝 剪枝1:奇偶剪 ...
随机推荐
- 基于任务的编程模型TAP
一.引言 在上两个专题中我为大家介绍.NET 1.0中的APM和.NET 2.0中的EAP,在使用前面两种模式进行异步编程的时候,大家多多少少肯定会感觉到实现起来比较麻烦, 首先我个人觉得,当使用AP ...
- java8 stream 流 例子
Trader raoul = new Trader("Raoul", "Cambridge"); Trader mario = new Trader(" ...
- 玩转 sublime3 第一弹 文件介绍
安装 官网下载地址:http://www.sublimetext.com/3 本文将以Windows 64 bit 进行讲解. 目录介绍 sublime默认安装之后会生成一个安装目录和数据目录: C: ...
- 关于函数调用约定-thiscall调用约定
函数调用约定描述了如何以正确的方式调用某些特定类型的函数.包括了函数参数在栈上的分配顺序.有哪些参数将通过寄存器传入,以及在函数返回时函数栈的回收方式等. 函数调用约定的几种类型 stdcall,cd ...
- Event-driven programming-main loop
In computer programming, event-driven programming is a programming paradigm in which the flow of the ...
- html css 样式中100%width 仍有白边解决办法
把 <body >改成<body style="margin=0%">
- JS取出特定字符前后的字符串,针对一串字符里面的单个字符前后的字符串
//针对一串自负里面的单个字符前后的字符串<!doctype html> <html> <head> <meta charset="utf-8&qu ...
- 8、Collaborative Metric Learning
一.摘要: 文章的核心思想:是如何把Metric learning 和 CF结合起来从而达到更好的推荐效果. 提出了CML(Collaborative Metric Learning),其学习一个联合 ...
- Activiti Workflow HelloWorld 示例与测试环境搭建
作者:Rock 出处:http://www.ecmkit.com/zh-hans/2012/03/21/activiti-workflow-hell Activiti Workflow HelloWo ...
- W10如何开启LinuxBash及安装Ubuntu
W10如何开启LinuxBash的功能 1)开启开发人员模式 2)启动部分windows功能 完成后重启系统 然后在cmd中输入bash按命令操作即可使用bash命令 3)下载安装ubuntu lxr ...