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)为此刻点到终点位置,由上面剪枝分析,两者之差一定为偶数。所以根据小学数学,奇-奇=偶,偶-偶=偶,可知两数奇偶性相同(有用吗)】

 1 #include<cstdio>
 2 #include<cmath>
 3 #include<cstring>
 4 #include<iostream>
 5 #include<algorithm>
 6 using namespace std;
 7 #define mem(a) memset(a,0,sizeof(a))
 8 #define ll long long
 9 int fa[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
10 int n,m,v;
11 char mo[10][10];
12 int mark[10][10];
13 int ans,x1,x2,y3,y2;
14 int coun;
15 int abs(int a)
16 {
17     if (a<0) return -a;
18     return a;
19 }
20 void dfs(int x,int y,int step)
21 {
22     if(ans) return ;
23     if(x==x2&&y==y2&&step==v) {ans=1;return ;}
24     int v1=v-step-(abs(x-x2)+abs(y-y2));
25     if(v1<0||v1&1)
26         return ;
27     for(int i=0;i<4;i++)
28     {
29         int xx=x+fa[i][0];
30         int yy=y+fa[i][1];
31         if(xx>=0&&xx<n&&yy>=0&&yy<m&&mark[xx][yy]==0&&mo[xx][yy]!='X')
32         {
33             mark[xx][yy]=1;
34             dfs(xx,yy,step+1);
35             if(ans) return ;
36             mark[xx][yy]=0;
37         }
38     }
39     return ;
40 }
41 int main()
42 {
43    while(~scanf("%d%d%d",&n,&m,&v)&&(n||m||v))
44    {
45        ans=coun=0;
46        mem(mark);
47        for(int i=0;i<n;i++)
48         scanf("%s",mo[i]);
49        for(int i=0;i<n;i++)
50        {
51            for(int j=0;j<m;j++)
52            {
53                if(mo[i][j]=='S')
54                {x1=i;y3=j;}
55                if(mo[i][j]=='D')
56                {x2=i;y2=j;}
57                if(mo[i][j]=='X')
58                 coun++;
59            }
60        }
61        if(v>n*m-coun-1)
62        {
63            printf("NO\n");
64            continue;
65        }
66        mark[x1][y3]=1;
67        dfs(x1,y3,0);
68        if(ans==1)printf("YES\n");
69        else printf("NO\n");
70    }
71   return 0;
72 }

View Code

转载于:https://www.cnblogs.com/XXrll/p/10164942.html

DFS Tempter of the Bone相关推荐

  1. Tempter of the Bone(DFS + 奇偶剪枝,好题)

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

  2. HDU1010 Tempter of the Bone DFS+剪枝

    点击打开链接 Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  3. HDU1010:Tempter of the Bone(dfs+剪枝)

    http://acm.hdu.edu.cn/showproblem.php?pid=1010   //题目链接 http://ycool.com/post/ymsvd2s//一个很好理解剪枝思想的博客 ...

  4. hdu1010 Tempter of the Bone

    转载自:http://acm.hdu.edu.cn/forum/read.php?tid=6158 sample input: 4 4 5 S.X. ..X. ..XD .... 问题: (1): 在 ...

  5. HDOJ 1010 HDU 1010 Tempter of the Bone ACM 1010 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目描述: 代码 ...

  6. 回溯法+奇偶剪枝——Hdu 1010 Tempter of the Bone

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

  7. HDU.1010 Tempter of the Bone

    文章目录 一.题目解读 1.原题 2.分类 3.题意 4.输入输出格式 5.数据范围 二.题解参考 1.总体思路 2.思路① (1).分析 (2).AC代码 三.评价与后话 1.评价 2.奇偶剪枝0- ...

  8. HDU1010 Tempter of the Bone(DFS奇偶剪枝)

    传送门 Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. Howe ...

  9. ZOJ 2110 Tempter of the Bone(DFS)

    点我看题目 题意 : 一个N×M的迷宫,D是门的位置,门会在第T秒开启,而开启时间小于1秒,问能否在T秒的时候到达门的位置,如果能输出YES,否则NO. 思路 :DFS一下就可以,不过要注意下一终止条 ...

最新文章

  1. 编译OpenSSH8.4的RPM包及升级
  2. html中inline函数,开窗函数和窗口函数区别 inline函数和一般的函数有什么不同
  3. MyEclipse导入eclipse的web项目,将WebRoot切换为WebContent
  4. 洛谷 P1091 合唱队型
  5. DRBD+keepalived+LAMP+discuz
  6. dsp怪胎_我是如何发现内心怪胎的
  7. 爆款预定!雷军再曝小米12 Pro:首发自研芯片澎湃P1
  8. oracle停止一切进程,oracle中expdp/impdp进程如何停止
  9. 同学,那些个证书没屌用!
  10. hi35xx stmmac网卡驱动源码解读
  11. 外企程序员常用英语单词
  12. Ubuntu下FileZilla的安装
  13. 克隆出错fatal: unable to access ‘https://github.com/‘: OpenSSL SSL_connect:
  14. 小学六年级下册计算机计划,小学信息技术六年级下册教学计划
  15. Mac下编译WebRTC(Mac和iOS版本)
  16. android wight
  17. C语言自制简单点菜系统
  18. 非全研究生业余研究:利用十一假期训练了室内定位模型
  19. 掌薪阁分享:一个人人可做,汇聚了全网不同层次的网赚项目!
  20. 当你输入信用卡号码的时候,有没有担心输错了而造成损失呢?其实可以不必这么担心,因为并不是一个随便的信用卡号码都是合法的,它必须通过Luhn算法来验证通过。 该校验的过程:1、从卡号最后一位数字开始,逆

热门文章

  1. javascript各种小技巧
  2. python爬虫如何从一个页面进入另一个页面-爬虫入门(一)——如何打开一个网页...
  3. python写网站和java写网站的区别-为什么说Java和Python现阶段并不适合普通网站建设...
  4. python 柱状图-python 柱状图
  5. python画图-Python 绘图,我只用 Matplotlib(二)
  6. python要不要装pycharm-Python和pyCharm安装
  7. python基本使用-Python 应该怎么去练习和使用?
  8. python使用界面-推荐8款常用的Python GUI图形界面开发框架
  9. python爬百度翻译-Python爬虫实现百度翻译功能过程详解
  10. python创建一个txt文件-python中如何创建一个txt文件