HDU 1010 Tempter of the Bone
来源:互联网 发布:2.5平衡口耳机 知乎 编辑:程序博客网 时间:2024/05/20 06:53
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010
题意很简单,就不说了,题目是说狗能不能正好在门开的那一刻到达迷宫出口处,走过的地方不能重复走。。题目有很多可以剪枝的地方。
1:如果能走的blocks本身就比时间少,剪枝。
2:奇偶剪枝。这也是这道题目的精华,最重要的一个剪枝。剩余的时间与当前位置到达出口的最小距离的奇偶性必须保持一致,否则不能到达。
这道题目用DFS做还是比较好的,合适的剪枝会让效率提高很多的。
#include<stdio.h>#include<math.h>#include<iostream>using namespace std;char map[9][9];int n,m,t;int di,dj;bool escape;int dir[4][2]={{0,-1},{0,1},{1,0},{-1,0}};void dfs(int si,int sj,int cnt){ int i,temp; if(si>n||sj>m||si<=0||sj<=0) return; if(si==di&&sj==dj&&cnt==t) { escape=1; return; } temp=(t-cnt)-(abs(si-di)+abs(sj-dj)); if(temp<0||temp%2) return; for(i=0;i<4;i++) { if(map[si+dir[i][0]][sj+dir[i][1]]!='X') { map[si+dir[i][0]][sj+dir[i][1]]='X'; dfs(si+dir[i][0],sj+dir[i][1],cnt+1); if(escape) return; map[si+dir[i][0]][sj+dir[i][1]]='.'; } } return;}int main(){ int i,j,k; int wall; int si,sj,cnt; while(scanf("%d%d%d",&n,&m,&t)!=EOF) { getchar(); wall=0; if(n==0||m==0||t==0) break; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { cin>>map[i][j]; if(map[i][j]=='S') { si=i; sj=j; } else if(map[i][j]=='D') { di=i; dj=j; } else if(map[i][j]=='X') { wall++; } } getchar(); } if(n*m-wall<=t) { printf("NO\n"); continue; } escape=0; map[si][sj]='X'; dfs(si,sj,0); if(escape) printf("YES\n"); else printf("NO\n"); } return 0;}
0 0
- HDU 1010 Tempter of the Bone
- 迷宫 hdu 1010 Tempter of the Bone
- HDU 1010-Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone(深搜)
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU-1010-Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU 1010-Tempter of the Bone
- HDU 1010 Tempter of the Bone (DFS)
- hdu 1010 Tempter of the Bone
- HDU 1010 - Tempter of the Bone
- hdu 1010 Tempter of the Bone
- 将博客搬至CSDN
- 就像大家更熟悉的const一样,volatile是一个类型修饰符(type specifier)。它是被设计用来修饰被不同线程访问和修改的变量。
- C#综合性实验 - 文本编辑器
- applicationContext.xml文件如何共引用另一个applicationContext.xml文件中的bean
- UC笔试题(二)
- HDU 1010 Tempter of the Bone
- Decorrelating Semantic Visual Attributes by Resisting the Urge to Share 论文笔记
- C++模板浅谈
- C++[算法]不借助第三个参数,交换两个数的值
- [Oracle] 分析函数(4)- Order By字句
- R语言编程艺术——考试成绩的回归分析[一]
- CDialog窗口类的Class Style中没有CS_VREDRAW和CS_HREDRAW导致自绘有问题
- 你妹都看得懂的手机网游制作教程(第21篇)游戏黑屏了,别急我们来调试代码
- C#,C++,Java三者的一些区别