HDOJ_1010 Tempter of the Bone
http://acm.hdu.edu.cn/showproblem.php?pid=1010
奇偶剪枝:
可以把map看成这样:
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
从为 0 的格子走一步,必然走向为 1 的格子
从为 1 的格子走一步,必然走向为 0 的格子
即:
0 ->1或1->0 必然是奇数步
0->0 走1->1 必然是偶数步
结论:
所以当遇到从 0 走向 0 但是要求时间是奇数的,或者, 从 1 走向 0 但是要求时间是偶数的 都可以直接判断不可达!
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define N 10 char maps[N][N];
int dir[][] = {{, }, {, }, {-, }, {, -}};
int m, n, t, sx, sy, ex, ey, f; void DFS(int x, int y , int d)
{
int i, a, b, p, q;
if(x < || x >= m || y < || y >= n)
return ;
if(x == ex && y == ey && d == t)f = ;
if(f == )
return ;
p = t - d;
q = abs(x - ex) + abs(y - ey);
if(p < q || (p % == && q % != ) || (p % != && q % == ))return ;
for(i = ; i < ; i++)
{
a = x + dir[i][];
b = y + dir[i][];
if(a >= && a < m && b >= && b < n && maps[a][b] != 'X')
{
maps[a][b] = 'X';
DFS(a, b, d + );
maps[a][b] = '.';
}
}
return ;
}
int main()
{
int i, j, wall;
while(scanf("%d%d%d", &m, &n, &t), m != || n != || t != )
{
f = wall = ;
for(i = ; i < m ; i++)
{
scanf(" ");
for(j = ; j < n ; j++)
{
scanf("%c", &maps[i][j]);
if(maps[i][j] == 'S')sx = i, sy = j;
else if(maps[i][j] == 'D')ex = i, ey = j;
else if(maps[i][j] == 'X')wall++;
}
}
if(m * n - wall < t)
{
printf("NO\n");
continue;
}
maps[sx][sy] = 'X';
DFS(sx, sy, );
if(f == )printf("YES\n");
else printf("NO\n");
}
return ;
}
HDOJ_1010 Tempter of the Bone的更多相关文章
- 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 ...
- ZOJ 2110 Tempter of the Bone
Tempter of the Bone Time Limit: 2 Seconds Memory Limit: 65536 KB The doggie found a bone in an ...
- 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
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- Hdu 1010 Tempter of the Bone 分类: Translation Mode 2014-08-04 16:11 82人阅读 评论(0) 收藏
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdoj 1010 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 深搜+剪枝
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 ...
随机推荐
- 如何将开源项目部分代码作为private放在github上?
很多时候,你的一些项目本身都是开源的,但是基于该开源项目,你可能做了部分更有价值的工作,或者由于其他原因,你不希望将这部分代码放到public上,那么有以下简单方法: 1. 创建一个private b ...
- 51nod1120 机器人走方格 V3
跟括号序列是一样的,将向右走看成是左括号向左走看成是右括号就可以了.那么就是卡特兰数了.然后由于n和m太大所以用了lucas定理 //跟括号序列是一样的,将向右走看成是左括号向左走看成是右括号就可以了 ...
- mysql 调用带返回值的存储过程
存储过程: create procedure proc_t(out uname varchar(50),out upwd varchar(50),in uid int) BEGIN select na ...
- BZOJ 1555 KD之死
贪心,按t+w排序维护不一定放到拖车上的大根堆. #include<iostream> #include<cstdio> #include<cstring> #in ...
- cakephp之查询
find public find( string $type 'first' , array $query array() ) Queries the datasource and returns a ...
- 20160201.CCPP体系详解(0011天)
内容概要:C语言基本数据类型及运算题库(含答案) 第二章 基本数据类型及运算 一.选择题 1. 若以下选项中的变量已正确定义,则正确的赋值语句是[C]. A) x1=26.8%3; B) 1+2=x2 ...
- Python [Leetcode 342]Power of Four
题目描述: Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Examp ...
- mysql装载本地文件及模式匹配
使用load data装载本地文件到表中,文件每行一条记录,列值之间用tab分隔,并按照次序一一列出,对于无值或丢失的情况可以使用\N.但是在使用insert into插入的时候不能使用\N,而应该是 ...
- linux shell中的 #!/bin/bash
#!/bin/bash是指此脚本使用/bin/bash来解释执行. 其中,#!是一个特殊的表示符,其后,跟着解释此脚本的shell路径. bash只是shell的一种,还有很多其它shell,如:sh ...
- svn sc create 命令行创建服务自启动
今天重装了系统,Subversion服务也得重装.照例输入代码: sc create svnserve binpath="d:\PortableApps\svn\svnserve.exe - ...