http://acm.hdu.edu.cn/showproblem.php?pid=1010

用到了奇偶剪枝:

0 1 0 1

1 0 1 0          如图,设起点为s,终点为e,s->e的最短步数为t.   sum=t+extra. [因为extra无论怎么走,最终都要返回其中一条最短路径上,即有来回,所以extra=2*某个数,一定是偶数。

0 1 0 1

1 0 1 0

【所以此题中,v-step表示还可以走多少步,abs(x-x2)+abs(y-y2)为此刻点到终点位置,由上面剪枝分析,两者之差一定为偶数。所以根据小学数学,奇-奇=偶,偶-偶=偶,可知两数奇偶性相同(有用吗)】

 #include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
int fa[][]={{,},{,-},{,},{-,}};
int n,m,v;
char mo[][];
int mark[][];
int ans,x1,x2,y3,y2;
int coun;
int abs(int a)
{
if (a<) return -a;
return a;
}
void dfs(int x,int y,int step)
{
if(ans) return ;
if(x==x2&&y==y2&&step==v) {ans=;return ;}
int v1=v-step-(abs(x-x2)+abs(y-y2));
if(v1<||v1&)
return ;
for(int i=;i<;i++)
{
int xx=x+fa[i][];
int yy=y+fa[i][];
if(xx>=&&xx<n&&yy>=&&yy<m&&mark[xx][yy]==&&mo[xx][yy]!='X')
{
mark[xx][yy]=;
dfs(xx,yy,step+);
if(ans) return ;
mark[xx][yy]=;
}
}
return ;
}
int main()
{
while(~scanf("%d%d%d",&n,&m,&v)&&(n||m||v))
{
ans=coun=;
mem(mark);
for(int i=;i<n;i++)
scanf("%s",mo[i]);
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(mo[i][j]=='S')
{x1=i;y3=j;}
if(mo[i][j]=='D')
{x2=i;y2=j;}
if(mo[i][j]=='X')
coun++;
}
}
if(v>n*m-coun-)
{
printf("NO\n");
continue;
}
mark[x1][y3]=;
dfs(x1,y3,);
if(ans==)printf("YES\n");
else printf("NO\n");
}
return ;
}

DFS Tempter of the Bone的更多相关文章

  1. DFS:Tempter of the Bone (规定时间达到规定地点)

    解题心得: 1.注意审题,此题是在规定的时间达到规定的地点,不能早到也不能晚到.并不是最简单的dfs 2.在规定时间达到规定的地点有几个剪枝: 一.公式:所需的步骤 - x相差行 - y相差列 = 偶 ...

  2. 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 ...

  3. 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 ...

  4. HDU 1010 Tempter of the Bone --- DFS

    HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...

  5. 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 ...

  6. Tempter of the Bone(dfs+奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  7. Tempter of the Bone(dfs奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  8. ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)

    题意  一仅仅狗要逃离迷宫  能够往上下左右4个方向走  每走一步耗时1s  每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次  问狗是否有可能逃离这个迷宫 直接DFS  直道找到满足条件的路径 ...

  9. 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 ...

随机推荐

  1. 第九单元 利用vi编辑器创建和编辑正文文件

    vi编辑器简介  什么是vi vi编辑器的操作模式 vi编辑器的3种基本模式 在vi编辑器中光标的移动 移动光标位置的键与光标移动间的关系 进入插入模式 从命令行模式进入插入模式的命令 在命令行模式下 ...

  2. Let the Balloon Rise <map>的应用

    Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the ...

  3. BrupSuite渗透测试笔记(九)

    一. Update BurpSuite 1.选择help ,点击check for updates 记可以进入最新版本的下载界面,profession version need pay for mon ...

  4. bzoj4821-线段树区间lazy_tag下放的优先级和区间覆盖

    见博客https://www.cnblogs.com/zwfymqz/p/8588693.html 题解链接https://blog.csdn.net/ripped/article/details/7 ...

  5. Linux/Unix/Mac OS下的远程访问和文件共享方式

    scp -P 20022 src.tar.gz zhouhh@192.168.12.13:/home/zhouhhscp -P 20022 zhouhh@192.168.12.13:/home/zho ...

  6. Java接口自动化测试之HTTPClient学习(四)

    pom.xml  文件中dependency <dependencies> <dependency> <groupId>org.testng</groupId ...

  7. Django的Session存储Redis环境配置

    第一步:在项目目录下的settings.py中MIDDLEWARE中加上中间件: # session中间件Django项目默认启用Session 'django.contrib.sessions.mi ...

  8. IDEA快捷键之for循环

    intelliJ生成for循环代码. 迭代器for循环 iter Iterate iterable | Array in J2SDK 5 syntax itar Iterate elements of ...

  9. caffe调loss方法

    正文 what should I do if... ...my loss diverges? (increases by order of magnitude, goes to inf. or NaN ...

  10. node.js vue-axios和vue-resource

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...