poj 1573 简单模拟
2013-01-04 19:17
351 查看
做几个简单模拟题
#include <iostream> #include <vector> #include <map> #include <list> #include <set> #include <deque> #include <stack> #include <queue> #include <algorithm> #include <cmath> #include <cctype> #include <cstdio> #include <iomanip> #include <cmath> #include <cstdio> #include <iostream> #include <string> #include <sstream> #include <cstring> #include <queue> using namespace std; ///宏定义 const int INF = 20000000; const int MAXN = 15; ///全局变量 和 函数 char maze[MAXN][MAXN]; bool vis[MAXN][MAXN]; int rows, cols, entry; int main() { ///变量定义 int i, j, k; ///操作执行 while(1) { scanf("%d %d %d", &rows, &cols, &entry); getchar(); if(rows == 0 && cols == 0 && entry == 0) break; for(i = 1; i <= rows; ++i) { gets(maze[i] + 1); } memset(vis, false, sizeof(vis)); bool flag = false; int posy, posx; int steps = 0; posy = 1; posx = entry; vis[posy][posx] = true; while(1) { steps++; if(maze[posy][posx] == 'N') { posy -= 1; } else if(maze[posy][posx] == 'W') { posx -= 1; } else if(maze[posy][posx] == 'S') { posy += 1; } else { posx += 1; } if(posy <= 0 || posy > rows || posx <= 0 || posx > cols) break; if(vis[posy][posx]) { flag = true; break; } else vis[posy][posx] = true; } if(flag) { memset(vis, false, sizeof(vis)); vis[posy][posx] = true; int cnt = 0; while(1) { cnt++; if(maze[posy][posx] == 'N') { posy -= 1; } else if(maze[posy][posx] == 'W') { posx -= 1; } else if(maze[posy][posx] == 'S') { posy += 1; } else { posx += 1; } if(vis[posy][posx]) { break; } else vis[posy][posx] = true; } printf("%d step(s) before a loop of %d step(s)\n", steps - cnt, cnt); } else printf("%d step(s) to exit\n", steps); } ///结束 return 0; }
相关文章推荐
- POJ 1573 && hdu 1035(简单模拟)
- POJ 1573 && hdu 1035 Robot Motion【简单模拟】
- POJ 1573 && hdu 1035 Robot Motion(简单模拟)
- POJ 1573 && hdu 1035 Robot Motion【简单模拟】
- poj_1573 Robot Motion(简单模拟)
- POJ 1573:Robot Motion:简单模拟
- POJ 1573 Robot Motion(简单模拟)
- poj1068 简单的括号匹配模拟
- poj 1573 Robot Motion 【模拟】【刷题计划】
- Distance on Chessboard POJ - 1657 简单模拟
- POJ 2105 IP Address(简单模拟)
- poj 1573 模拟
- POJ 3414 Pots(简单模拟+dfs)
- poj 3083 Children of the Candy Corn (广搜,模拟,简单)
- POJ 3032 简单队列模拟
- POJ 1028 Web Navigation(简单模拟)
- POJ 1132 Border(边界) 简单模拟
- POJ 1573 Robot Motion 模拟
- POJ 1886简单模拟
- poj-1573-Robot Motion--模拟