hdu 1035 Robot Motion
来源:互联网 发布:数学试卷编辑软件 编辑:程序博客网 时间:2024/06/06 00:33
hdu 1035 Robot Motion
深搜。
#include <stdio.h>#include <string.h>#define MAX_N 11char map[MAX_N][MAX_N];int visited[MAX_N][MAX_N];int n, m;int sx, sy;int step, loopStep;bool dfs(int x, int y, int* s) {if (x < 1 || x > n || y < 1 || y > m) {return false;}else if (visited[x][y] != -1) {loopStep = visited[x][y];return true;}visited[x][y] = (*s)++;if (map[x][y] == 'N') {return dfs(x -1, y, s);} else if (map[x][y] == 'S') {return dfs(x + 1, y, s);} else if (map[x][y] == 'W') {return dfs(x, y - 1, s);} else if (map[x][y] == 'E') {return dfs(x, y + 1, s);}return false;}int main() {int i, j;while (scanf("%d%d", &n, &m) != EOF && n || m) {scanf("%d", &sy);for (i = 1; i <= n; i++) {scanf("%s", map[i] + 1);}sx = 1;loopStep = step = 0;memset(visited, -1, sizeof(visited));if (dfs(sx, sy, &step)) {printf("%d step(s) before a loop of %d step(s)\n", loopStep, step - loopStep); } else {printf("%d step(s) to exit\n", step);}}return 0;}
- hdu 1035 Robot Motion
- HDU 1035 Robot Motion
- hdu 1035 Robot Motion
- hdu 1035 Robot Motion
- hdu 1035 Robot Motion
- HDU 1035 Robot Motion
- hdu 1035 Robot Motion
- hdu 1035 robot motion
- HDU-1035Robot Motion
- hdu 1035 Robot Motion
- Robot Motion HDU 1035
- (hdu)1035 Robot Motion
- hdu 1035 Robot Motion
- HDU 1035 - Robot Motion
- HDU 1035 Robot Motion
- HDU 1035 Robot Motion
- hdu 1035 Robot Motion
- HDU 1035 Robot Motion
- PowerDesigner 15.1逆向工程MySQL
- Ubuntu下彻底卸载mysql
- Liunx redhat 下删除自带的 OpenJDK
- JAVA抽象类和接口
- hdu4740
- hdu 1035 Robot Motion
- linux下解压命令大全
- 字符串操作 replace 自己改的
- hdu 4741 Save Labman No.004
- 安装gstreamer-0.10.29
- redhat linux 5.6下安装jdk和tomcat
- Linux下递归列出仅所有常规文件或文件夹路径的方法
- 如何在UIimageview里显示一张图片里的某一部分
- lua+VS环境搭建