zoj 2110 Tempter of the Bone【邻接阵,dfs】
2012-10-31 20:11
369 查看
题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1110
大致题意:第一行n,m,t代表n行m列的图,t是门开的时间,门开不超过1s。
接下来n行m列的图。
'.'代表通路
'X'代表墙
'S'代表初始位置
'D'代表门的位置
要求必须在t秒钟从S到达D,能到输出YES,否则输出NO。
大致题意:第一行n,m,t代表n行m列的图,t是门开的时间,门开不超过1s。
接下来n行m列的图。
'.'代表通路
'X'代表墙
'S'代表初始位置
'D'代表门的位置
要求必须在t秒钟从S到达D,能到输出YES,否则输出NO。
#include<stdio.h> char gird[8][8]; int n, m, t, ans, a1, b1; void dfs(int i, int j, int k) { if(i == a1 && j == b1 && k == t) { ans = 1; return ; } gird[i][j] = 'X'; if(j+1 <= m && gird[i][j+1] != 'X') { dfs(i, j+1, k+1); if(ans) return ; } if(i+1 <= n && gird[i+1][j] != 'X') { dfs(i+1, j, k+1); if(ans) return ; } if(i-1 >= 1 && gird[i-1][j] != 'X') { dfs(i-1, j, k+1); if(ans) return ; } if(j-1 >= 1 && gird[i][j-1] != 'X') { dfs(i, j-1, k+1); if(ans) return ; } gird[i][j] = '.'; } int main() { while(scanf("%d %d %d%*c", &n, &m, &t) , n+m+t) { int a, b; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { scanf("%c", &gird[i][j]); if(gird[i][j] == 'S') { a = i; b = j; } if(gird[i][j] == 'D') { a1 = i; b1 = j; } } scanf("%*c"); } ans = 0; dfs(a, b, 0); if(ans) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
相关文章推荐
- ZOJ 2110 ( HDU 1010 ) Tempter of the Bone( 比较经典的DFS) --from lanshui_Yang
- HDU 1010 && ZOJ 2110 Tempter of the bone (DFS + 奇偶剪枝)
- ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)
- ZOJ 2110 Tempter of the Bone (DFS+减枝)
- ZOJ 2110 Tempter of the Bone (DFS)
- ZOJ 2110 Tempter of the Bone (DFS+减枝)
- zoj 2110 Tempter of the Bone (dfs)
- zoj-2110-Tempter of the Bone-DFS-剪枝-java
- zoj(2110)Tempter of the Bone(DFS+奇偶剪枝)
- ZOJ 2110 Tempter of the Bone(DFS)
- ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)
- HDU 1010 ZOJ 2110 Tempter of the Bone (DFS 奇偶剪枝)
- HDU 1010 Tempter of the Bone &&ZOJ 2110【DFS】
- HDU 1010 && ZOJ 2110--Tempter of the Bone【DFS && 奇偶剪枝】
- zoj 2110 || hdoj 1010 Tempter of the Bone(DFS)
- zoj 2110 Tempter of the Bone(DFS+奇偶剪枝及优化操作)
- Tempter of the Bone_ZOJ 2110
- Tempter of the Bone 回溯法 hdu1010 zoj2110
- ZOJ 2110 Tempter of the Bone
- zoj2110-Tempter of the Bone