Qiuqiqiu  
不管道路多么崎岖坎坷,我永远不停下追逐梦想的脚步!

http://acm.hdu.edu.cn/showproblem.php?pid=1035

不知道为什么这也是搜索题,分明就是模拟题

我的代码
 1 #include <stdio.h>
2 #include <string.h>
3 const int N=15;
4 const int dx[4]={0,1,0,-1};
5 const int dy[4]={1,0,-1,0};
6 char maze[N][N];
7 int n,m,cnt,x,y;
8 int vis[N][N];
9 int main()
10 {
11 int d,i;
12 while (scanf("%d%d%d",&n,&m,&y),n||m)
13 {
14 x=1; cnt=0;
15 memset(vis,0,sizeof(vis));
16 memset(maze,0,sizeof(maze));
17 for (i=1;i<=n;i++) scanf("%s",maze[i]+1);
18 while (1)
19 {
20 if (!maze[x][y])
21 {
22 printf("%d step(s) to exit\n",cnt);
23 break;
24 }
25 if (vis[x][y])
26 {
27 printf("%d step(s) before a loop of %d step(s)\n",vis[x][y]-1,cnt-vis[x][y]+1);
28 break;
29 }
30 vis[x][y]=++cnt;
31 switch (maze[x][y])
32 {
33 case 'E': d=0; break;
34 case 'S': d=1; break;
35 case 'W': d=2; break;
36 case 'N': d=3; break;
37 }
38 x+=dx[d]; y+=dy[d];
39 }
40 }
41 return 0;
42 }

 

posted on 2012-01-13 17:46  Qiuqiqiu  阅读(196)  评论(0编辑  收藏  举报