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:奇偶剪 ...
随机推荐
- Centos7 minimal 系列之rabbitmq的理解(九)
一.前言 传送门:rabbitmq安装 第一次接触消息队列,有很多不熟悉的地方,可能也有很多写的不对的,大家一起学习. RabbitMQ是一个在AMQP基础上完成的,可复用的企业消息系统. 使用场景: ...
- sql导出到excel
1.先查询数据ID,别名 导出到excel 2.增加标准名称,标识错误数据,导入sqlServer select distinct [StandardName] from [GMSOA].[dbo] ...
- jQuery对象与DOM对象的区别
如何判断一个js对象是否一个DOM对象 我们在写js代码时有时需要判断某个对象是不是DOM对象,然后再进行后续的操作,这里我给出一种兼容各大浏览器,同时又算是比较稳妥的一种方法. 要判断一个对象是否D ...
- Android 给WebView设置Cookie
最近项目中用到WebView访问新浪支付页面,有个要求是必须是登录状态,否则会报Token过期,然后我简单的将我从cookie中取得的ticket,即一串数字可以代表用户登录的唯一标识作为参数拼接到u ...
- pixhawk入门知识
Pixhawk是一种先进的自动驾驶仪,由PX4开放硬件项目设计和3D机器人制造.它具有来自ST公司先进的处理器和传感器技术,以及NuttX实时操作系统,能够实现惊人的性能,灵活性和可靠性控制任何自主飞 ...
- Lost Cows POJ - 2182 二分 + 树状数组
Code: #include<cstdio> #include<stack> #include<cstring> #include<algorithm> ...
- 再次理解JS的prototype,__proto__和constructor
个人总结: 下面这篇文章很好的讲解了js原型,原型链,个人的总结是要记住这三个属性 prototype.__proto__和constructor 首先明确,js中一切都是对象object(A). ( ...
- ajax常用知识
同源地址:任意两个地址中的协议,域名,端口相同,称为同源地址 同源策略: 是浏览器的一种基本安全策略 不允许对非同源地址进行请求(ajax) ...
- php的更新
因为 PHP 那“集百家之长”的蛋疼语法,加上社区氛围不好,很多人对新版本,新特征并无兴趣.本文将会介绍自 PHP5.2 起,直至 PHP5.6 中增加的新特征 本文目录:PHP5.2 以前:auto ...
- Android开发进度06
1,今日:目标:完成后台账单的增删改查 2,昨天:用户的增删改查 3,收获:熟练了SQLite操作 4,问题:无