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:奇偶剪 ...
随机推荐
- week5_notebooke1
大纲: 01 装饰器进阶 02 函数的有效信息 03 可迭代对象.迭代器 04 生成器 列表生成式 生成器表达式 05 内置函数 06 二分查找 01 装饰器进阶 #多个装饰器装饰同一个函数: ## ...
- 数据库自动备份压缩脚本(备份最近七天,七天之前自动删除,只保留rar文件)
把下面脚本添加到服务器计划任务中去,设置为每天执行即可,文件备份路径即为脚本所在路径,必须安装压缩文件 @echo offrem 计算指定天数之前的日期,用于后面删除指定天数的数据set DaysAg ...
- hdu 1166 敌兵布阵 【线段树】
好好学一下线段树---- 从0开始----加油- 单点更新的 #include<cstdio> #include<cstring> #include<iostream&g ...
- 并发编程——全局解释器锁GIL
1.全局解释器锁GIL GIL其实就是一把互斥锁(牺牲了效率但是保证了数据的安全). 线程是执行单位,但是不能直接运行,需要先拿到python解释器解释之后才能被cpu执行 同一时刻同一个进程内多个线 ...
- Python 九九乘法表打印
Python 九九乘法表打印 小练习 for i in range(1,10,1): for j in range(1,i+1): print("%s*%s=%s" %(j,i,i ...
- CF508E (贪心+搜索+构造)
题目大意:让你构造一个括号序列,括号匹配的方式类似于栈,给出从左数每个括号 到和它匹配的右括号的 最小和最大距离,让你输出一个合法括号序列 看错题了以为是二分图,然后写了搜索 贪心发现如果距离往小了填 ...
- Python发行版本Anaconda的安装说明:基于Anaconda2-4.3.1-Windows-x86_64
Anaconda指的是一个开源的Python发行版本,其包含了conda.Python等180多个科学包及其依赖项.因为包含了大量的科学包,Anaconda 的下载文件比较大(约 531 MB),如果 ...
- Lapack下载安装
安装 1.下载压缩文件 wget http://www.netlib.org/lapack/lapack-3.8.0.tar.gz 2.解压缩 tar -zxvf lapack-3.8.0.tar.g ...
- Jquery JS 全局变量
window["a1"]="abc";window["b1"]=5;
- spring mvc 下载的时候中文文件名不显示
Headers.add("Content-Disposition", "attachment;filename=" + new String(file.getB ...