【奇偶剪枝】HDU 1010 Tempter of the Bone
来源:互联网 发布:兄贵pat it 编辑:程序博客网 时间:2024/05/01 14:13
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010
剪枝:
1.奇偶剪枝:abs(sx-ex)+abs(sy-ey)为起点到终点的最短步数,若最短步数与要求步数t奇偶性不同,则不可能走到
2.当前步数不能大于t
3.图中'.'的数量+2<=t则不能走到
#include<stdio.h>#include<string.h>#include<math.h>#define MAXN 10char map[MAXN][MAXN];int n,m,t,sx,sy,ex,ey,flag;int dir[4][2]={0,1,1,0,0,-1,-1,0};void dfs(int x,int y,int tt){if(tt>t||flag) return ;if(tt==t&&x==ex&&y==ey){flag=1;return ;}if((abs(x-ex)+abs(y-ey))%2!=(t-tt)%2) return ;for(int i=0;i<4;i++){int xx=x+dir[i][0],yy=y+dir[i][1];if(xx<0||xx>=n||yy<0||yy>=m||map[xx][yy]=='X') continue;map[xx][yy]='X';dfs(xx,yy,tt+1);map[xx][yy]='.';}}char s[15];int main(){while(scanf("%d%d%d",&n,&m,&t)!=EOF&&(n+m+t)){int cnt=0;for(int i=0;i<n;i++){scanf("%s",&map[i]);for(int j=0;j<m;j++)if(map[i][j]=='S')sx=i,sy=j;else if(map[i][j]=='D')ex=i,ey=j;else if(map[i][j]=='.')cnt++;}if(abs(sx-ex)+abs(sy-ey)>t||cnt+2<=t||(t-abs(sx-ex)-abs(sy-ey))%2){printf("NO\n");continue;}map[ex][ey]='.';map[sx][sy]='X';flag=0;dfs(sx,sy,0);if(flag) printf("YES\n");else printf("NO\n");}return 0;}
0 0
- hdu 1010Tempter 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(DFS+奇偶剪枝)
- hdu 1010 Tempter of the Bone(dfs+奇偶剪枝)
- hdu 1010 Tempter of the Bone(dfs+奇偶剪枝)
- HDU--1010 -- Tempter of the Bone [DFS+经典奇偶剪枝]
- HDU 1010Tempter of the Bone(奇偶剪枝回溯dfs)
- Hdu 1010 Tempter of the Bone (DFS 经典奇偶剪枝)
- hdu 1010 Tempter of the Bone (dfs+奇偶剪枝)
- HDU 1010 Tempter of the Bone( DFS + 奇偶剪枝 )
- hdu 1010 Tempter of the Bone(dfs + 奇偶剪枝)
- HDU 1010 Tempter of the Bone ( dfs + 奇偶剪枝 )
- HDU 1010 Tempter of the Bone (DFS+奇偶剪枝)
- 【奇偶剪枝】HDU 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone(DFS+奇偶剪枝)
- HDU 1010-Tempter of the Bone(DFS+奇偶剪枝)
- Android Service在测试工程中使用的注意事项
- 要想快,先慢下来
- 使用aireplay-ng时报错“mon0 is on channel ×, but the AP uses channel ×”
- Ubuntu中解决解压zip文件中文乱码问题
- Struts2源码试读1-filter
- 【奇偶剪枝】HDU 1010 Tempter of the Bone
- memcpy的自定义实现的源代码
- hdu oj 2544 最短路(最短路径)
- nyoj 107
- 键盘快捷键
- 使用BlockingQueue进行多线程间的异步通信
- Java 同步与锁
- 字典树
- 进程&线程&死锁