hdu 1010 Tempter of the Bone
来源:互联网 发布:宁波淘宝直播招聘 编辑:程序博客网 时间:2024/06/06 00:51
本题链接:点击打开链接
本题为简单的DFS深搜题,不过还是写了好久,粗心啊。。。
AC代码:
#include<stdio.h>#include<math.h>#include<string.h>char map[10][10];int mark[10][10];int dx[]={1,-1,0,0};int dy[]={0,0,1,-1};int n,m,ti,flag,ex,ey,sx,sy;void dfs(int x,int y,int t){if(x<0||x>=n||y<0||y>=m)return ;if(flag||(t==0&&x==ex&&y==ey)){flag=1;return ;}int temp=t-abs(x-ex)-abs(y-ey);if(temp<0||temp&1)return ;map[x][y]='X';if(map[x+1][y]!='X'){dfs(x+1,y,t-1);if(flag)return ;}if(map[x][y+1]!='X'){dfs(x,y+1,t-1);if(flag)return ;}if(map[x-1][y]!='X'){dfs(x-1,y,t-1);if(flag)return ;}if(map[x][y-1]!='X'){dfs(x,y-1,t-1);if(flag)return ;}map[x][y]='.';}int main(){int i,j,wall;while(scanf("%d%d%d",&n,&m,&ti)!=EOF&&(n||m||ti)){wall=0;flag=0;for(i=0;i<n;i++){scanf("%s",map[i]);for(j=0;j<m;j++){if(map[i][j]=='S'){sx=i;sy=j;}if(map[i][j]=='D'){ex=i;ey=j;}if(map[i][j]=='X')wall++;}}dfs(sx,sy,ti);if(n*m-wall<=ti){printf("NO\n");continue;}if(flag)printf("YES\n");elseprintf("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
- List泛型集合
- java大数模板
- 8.5学习总结
- zoj 2100 Seeding
- Android Studio的使用
- hdu 1010 Tempter of the Bone
- 虚拟化项目之运维实践10
- UILabel
- 机器学习中的范数规则化之(二)核范数与规则项参数选择
- 20150805 oracle笔记
- leetcode 092 —— Reverse Linked List II
- UICollectionView基本使用方法
- Binary Tree Maximum Path Sum
- Java IO