HDU 1010 Tempter of the Bone
来源:互联网 发布:将java程序打包成exe 编辑:程序博客网 时间:2024/06/03 06:14
题目地址: ttp://acm.hdu.edu.cn/showproblem.php?pid=1010
大致题意:给定迷宫、出口和入口,走迷宫,走过的格子不能再走,每个格子最多停留1秒,出口会在特定的时间打开,只有在出口打开时,才能走出迷宫。判断能否走出迷宫。
思路:DFS+剪枝
剪枝:起点到终点的距离和时间奇偶性不同,舍去
注意:在DFS中恢复改变的格子的状态
#include <cstdio>#include <cstring>#include <cstdlib>using namespace std;void dfs(int,int,int);char a[7][7];int sx, sy, dx, dy;int d[][2] = { { 1, 0 }, { -1, 0 }, { 0, 1 }, {0,-1} };int m, n, t;bool find=false;int main(void){freopen("checker.out", "w", stdout);while (scanf("%d %d %d", &n, &m, &t) && m && n && t){memset(a, 0, sizeof(a));find = false;for (int i = 0; i < n; ++i)for (int j = 0; j < m; ++j){scanf("%1s", &a[i][j]);if (a[i][j] == 'S'){sx = i;sy = j;}if (a[i][j] == 'D'){dx = i;dy = j;}}dfs(sx, sy, t);if (find)printf("YES\n");elseprintf("NO\n");}return 0;}void dfs(int x, int y,int time){int sum = abs(dx - x) + abs(dy - y);if (sum > time || !((time - sum) % 2))return;if (time == 0){if (x == dx && y == dy)find = true;}else{int i = 0;for (; i < 4 && !find; ++i){int x1= x + d[i][0];int y1 = y + d[i][1];if (x1 >= 0 && x1 < n && y1 >= 0 && y1 < m && a[x1][y1] != 'X'){a[x1][y1] = 'X';dfs(x1, y1,time - 1);a[x1][y1] = '.';}}}}
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
- 如何解决Windows Server 2008 服务启动不能调用Office Word的问题
- 湘潭大学校赛A Love Letter
- cocos2dx-3.0(7)------Label、LabelTTF、LabelAtlas、LabelBMFont使用之法
- 在VMware安装Ubuntu后一直停留在VMware Easy Install
- Checkio: Roman numerals
- HDU 1010 Tempter of the Bone
- JAVA File类 分析(一)
- WF1300701 第三阶段项目日报 4
- 优化的真谛
- 神奇的C语言十九:C语言的内存分配
- java加密的强随机数生成器
- WF130701 陈帆 第三阶段项目日报 5
- JAVA单例模式理解
- WF130701 第三阶段项目日报 6