POJ 1573 Robot Motion
2015-04-01 23:00
309 查看
这是一题水水的模拟题。
#include <stdio.h> #include <string.h> #define mem(a) memset(a, 0, sizeof(a)) char map[15][15]; int m, n, s, shu[15][15]; bool vis[15][15]; void res(int x, int y, int num) { if(x < 0||x >= m||y < 0||y >= n) { printf("%d step(s) to exit\n", num - 1); return; } if(vis[x][y] == 1) { printf("%d step(s) before a loop of %d step(s)\n", shu[x][y] - 1, num - shu[x][y]); return; } shu[x][y] = num; if(map[x][y] == 'W'&&vis[x][y] == 0) { vis[x][y] = 1; res(x, y - 1, num + 1); } else if(map[x][y] == 'E'&&vis[x][y] == 0) { vis[x][y] = 1; res(x, y + 1, num + 1); } else if(map[x][y] == 'N'&&vis[x][y] == 0) { vis[x][y] = 1; res(x - 1, y, num + 1); } else if(map[x][y] == 'S'&&vis[x][y] == 0) { vis[x][y] = 1; res(x + 1, y, num + 1); } } int main(int argc, char *argv[]) { int i, j; for(;;) { mem(map); mem(vis); mem(shu); scanf("%d%d%d%*c",&m, &n, &s); if(m == 0&&n == 0&&s == 0) break; for(i = 0;i < m;i++) { for(j = 0;j < n;j++) { scanf("%c", &map[i][j]); if(j == (n - 1)) scanf("%*c"); } } res(0, s - 1, 1); } return 0; }
相关文章推荐
- poj 1573 Robot Motion
- POJ -1573 Robot Motion
- POJ 1573 Robot Motion 模拟
- POJ 1573, Robot Motion
- POJ-1573-Robot Motion-2013-12-15 00:46:22
- poj 1573 Robot Motion 模拟
- poj 1573 Robot Motion
- <poj-1573>Robot Motion
- poj 1573 Robot Motion
- POJ 1573 Robot Motion 模拟
- poj 1573 Robot Motion
- POJ 1573:Robot Motion
- poj 1573 Robot Motion
- POJ 1573 Robot Motion (DFS)
- poj-1573-Robot Motion--模拟
- Robot Motion(POJ 1573 模拟题)
- POJ 1573 Robot Motion (模拟+不回溯的dfs 水题)
- POJ 一 1573 Robot Motion
- POJ 1573 Robot Motion(DFS)
- poj 1573 Robot Motion