HDOJ 1010 Tempter of the Bone
来源:互联网 发布:js 调用windows程序 编辑:程序博客网 时间:2024/06/06 02:48
戳此看题
骨头的诱惑
题目大意:
小狗要逃出迷宫,迷宫的门当且仅当第T秒时打开,只有小狗在T秒到达迷宫的门才能成功逃脱。迷宫是一个N*M的矩形,每秒钟小狗可以向它的前后左右四个相邻的方格移动一下,小狗在每个方格中停留不能超过1秒,也不能回到经过的方格。小狗是否能成功逃脱?
解题思路:
深搜,并且要有回溯。
AC代码:
#include <stdio.h>#include <stdlib.h>#include <math.h>char map[9][9];int n,m,t;int di,dj,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==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(si+dir[i][0]>0&&si+dir[i][0]<=n&&sj+dir[i][1]>0&&sj+dir[i][1]<=m) 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,si,sj,wall;char ch; while(scanf("%d%d%d",&n,&m,&t)!=EOF) { if(n==0&&m==0&&t==0) break; wall=0;scanf("%c",&ch); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { scanf("%c",&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++; }scanf("%c",&ch); } 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;}
- hdoj 1010 Tempter of the Bone
- HDOJ 1010 Tempter of the Bone
- HDOJ 1010 Tempter of the Bone
- HDOJ 1010 Tempter of the Bone
- ACM HDOJ 1010 (Tempter of the Bone)
- HDOJ 1010 Tempter of the Bone
- HDOJ 1010 Tempter of the Bone
- HDoj-1010-Tempter of the Bone-DFS
- 【HDOJ 1010】Tempter of the Bone
- hdoj 1010 Tempter of the Bone
- hdoj 1010Tempter of the Bone【DFS】
- HDOJ 1010 Tempter of the Bone
- HDOJ 1010 Tempter of the Bone
- HDOJ 1010-Tempter of the Bone【dfs】
- HDOJ 1010 Tempter of the Bone
- HDOJ.1010 Tempter of the Bone (DFS)
- hdoj 1010 Tempter of the Bone
- HDOJ HDU 1010 Tempter of the Bone
- java单例模式
- JS--命名空间的理解(namespace)
- 字体问题
- java求输入两个数的最大公约数和最小公倍数
- Windows下安装OpenSSL
- HDOJ 1010 Tempter of the Bone
- 浅谈S3C2440的中断寄存器及中断过程
- Mac下隐藏以及显示文件的命令
- cocos2d-x扩展库CCControlSwitch的使用方法
- ssh 远程登录过去不用密码 ssh-keygen -t rsa
- MYSQL 编码格式的设置
- InstallShield 获得用户选择的安装语言
- BMP转JPG(法一)使用jpeglib库实现bmp转jpg (转)
- 联想