hdu1010 Tempter of the Bone(dfs) java
来源:互联网 发布:知道mac地址怎么查ip 编辑:程序博客网 时间:2024/05/22 17:11
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010
* 题意:根据地图,'S'为开始位置,'D'为门的位置,' . '为空地,'X'为墙,不能经过,
问:在指定的时间,是否能到达'门'的位置.
*/
package dfs;import java.util.Scanner;public class hdu1010 {static int d[][] = { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 } };static int MAX_N=10;static char map[][]=new char[MAX_N][MAX_N];static boolean vis[][]=new boolean[MAX_N][MAX_N];static int n,m,t,dx,dy;public static void main(String[] args) {// TODO Auto-generated method stubScanner scan=new Scanner(System.in);while(scan.hasNext()){n=scan.nextInt();m=scan.nextInt();t=scan.nextInt();if(n+m+t==0){break;}scan.nextLine();int x=0,y=0;for(int i=0;i<n;i++){String str=scan.nextLine();char a[]=str.toCharArray();for(int j=0;j<m;j++){map[i][j]=a[j];if(map[i][j]=='s'){x=i;y=j;map[i][j]='.';}if(map[i][j]=='D'){dx=i;dy=j;}}}int step=0;init();int res=dfs(x,y,step);if(res==0){System.out.println("NO");}else{System.out.println("YES");}}}private static int dfs(int x, int y, int step) {// TODO Auto-generated method stubif(step>t){return 0;}if(map[x][y]=='D'){return step;}for(int i=0;i<4;i++){int sx=x+d[i][0];int sy=y+d[i][1];if(ok(sx,sy)&&!vis[sx][sy]&&map[sx][sy]!='X'){vis[sx][sy]=true;dfs(sx,sy,step+1);vis[sx][sy]=false;}}return 0;}private static boolean ok(int sx, int sy) {// TODO Auto-generated method stubif(sx<0||sx>=n||sy<0||sy>=m){return false;}return true;}private static void init() {// TODO Auto-generated method stubfor(int i=0;i<MAX_N;i++){for(int j=0;j<MAX_N;j++){vis[i][j]=false;}}}}
阅读全文
0 0
- hdu1010 Tempter of the Bone(dfs) java
- hdu1010 Tempter of the Bone(DFS)
- hdu1010 Tempter of the Bone (DFS)
- HDU1010:Tempter of the Bone(DFS)
- Tempter of the Bone(hdu1010,dfs)
- 【搜索-DFS】hdu1010 Tempter of the Bone
- HDU1010 Tempter of the Bone 【DFS】+【剪枝】
- hdu1010 Tempter of the Bone(dfs)
- hdu1010 Tempter of the Bone(dfs)
- HDU1010 Tempter of the Bone DFS+剪枝
- DFS+剪枝 hdu1010 Tempter of the Bone
- hdu1010 Tempter of the Bone(DFS+剪枝)
- HDU1010 Tempter of the Bone (DFS)
- HDU1010 Tempter of the Bone DFS
- HDU1010:Tempter of the Bone(DFS)
- HDU1010:Tempter of the Bone(DFS)
- hdu1010 Tempter of the Bone(dfs)
- hdu1010 Tempter of the Bone(dfs+剪枝)
- 进程间互斥、同步
- java 反射机制-学习笔记(3)
- 顺序存储的稀疏矩阵(三元组)的转置
- 从铁路技术装备展的科技“攀比”看合作共赢
- POJ 3080.Blue Jeans
- hdu1010 Tempter of the Bone(dfs) java
- VS2012尝试运行项目时出错 无法启动程序 请参见应用程序日志时间
- 强连通分量——tarjan
- 第二讲 类加载器
- Leetcode 5. Longest Palindromic Substring(java版)
- 4 Values whose Sum is 0(poj 2785)
- shiro的org.apache.shiro.UnavailableSecurityManagerException错误
- a messy week
- Java/JDK配置环境变量