HDU 1010--Tempter of the Bone
来源:互联网 发布:菲律宾4g网络制式 编辑:程序博客网 时间:2024/06/08 18:11
题目:这是题目
题意:一只狗狗在一个迷宫里面要从门出去,但是门只在第T时间开一次,狗狗一定要在这个时间点出去,并且狗狗走过的路会消失,问是否狗狗能从门走出迷宫?
思路:这个题爆搜会T,要用奇偶剪枝,即T和狗狗到门的曼哈顿距离的奇偶一定要一样。
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <math.h>using namespace std;const int MAX = 10;int ti;int n, m, t;char _map[MAX][MAX];bool visit[MAX][MAX];int d[MAX][MAX];int x[4] = {0, 1, 0, -1};int y[4] = {-1, 0, 1, 0};int dis(int x1, int y1, int x2, int y2) { return (abs(x2 - x1) + abs(y2 - y1));}//计算曼哈顿距离bool dfs(int xx, int yy, int time) { if (_map[xx][yy] == 'D' && time == t) { return true; }//正好是t时刻到门则能到达 else { for (int i = 0; i < 4; i++) { int xi = xx + x[i]; int yi = yy + y[i];// cout << "$$ " << xi << " " << yi << endl; if (xi >= 0 && xi < n && yi >= 0 && yi < m && !visit[xi][yi]) {// cout << "ok " << xi << " " << yi << endl; time += 1; visit[xi][yi] = true; if (dfs(xi, yi, time)) { return true; } time -= 1; visit[xi][yi] = false; } } } return false;}int main() { while(scanf("%d%d%d", &n,&m,&t) != EOF) { if (n == 0 && m == 0 && t == 0) break; getchar(); int sx, sy, ex, ey; ti = 100; memset(visit, false, sizeof(visit)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { scanf("%c", &_map[i][j]); if (_map[i][j] == 'S') { sx = i; sy = j; visit[sx][sy] = true; } else if (_map[i][j] == 'D') { ex = i; ey = j; } else if (_map[i][j] == 'X') visit[i][j] = true; } getchar(); } if (dis(sx, sy, ex, ey) % 2 == t % 2) {//剪枝 if (dfs(sx, sy, 0)) printf("YES\n"); else printf("NO\n"); } else { printf("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
- html中内联数据的样式调整
- [架构] ZeroMQ 深度探索(一)
- linux操作系统与应用程序的main函数
- 电脑快捷键大全
- 基本设置与运行
- HDU 1010--Tempter of the Bone
- OK6410看门狗
- java编程300例:7.根据用户的消费情况计算用户的享受的折扣
- Linux系统性能监控命令详解
- Unofficial Windows Binaries for Python Extension Packages
- hdu 3652 B-number(数位dp)
- 关于使用libcurl的注意事项
- Linux GCC常用命令
- Python练习100例-5