POJ-1573 Robot Motion 模拟水题

  题目链接:http://poj.org/problem?id=1573

  随便模拟,水水~

 1 //STATUS:G++_AC_0MS_696KB
 2 #include<stdio.h>
 3 #include<stdlib.h>
 4 #include<string.h>
 5 #include<math.h>
 6 #include<iostream>
 7 #include<string>
 8 #include<algorithm>
 9 #include<vector>
10 #include<queue>
11 #include<stack>
12 using namespace std;
13 #define LL __int64
14 #define pii pair<int,int>
15 #define Max(a,b) ((a)>(b)?(a):(b))
16 #define Min(a,b) ((a)<(b)?(a):(b))
17 #define mem(a,b) memset(a,b,sizeof(a))
18 #define lson l,mid,rt<<1
19 #define rson mid+1,r,rt<<1|1
20 const int MAX=110,INF=0x3f3f3f3f,MOD=1999997;
21 const LL LLNF=0x3f3f3f3f3f3f3f3fLL;
22 
23 char map[MAX][MAX];
24 int ma[128],dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
25 int n,m,s,ans1,ans2;
26 
27 int dfs(int x,int y,int d)
28 {
29     int t=map[x][y];
30     if(x<0||x>=n || y<0||y>=m){
31         ans1=d;
32         return 1;
33     }
34     if(t<'A'){
35         ans1=t;ans2=d-t;
36         return 0;
37     }
38     map[x][y]=d;
39     dfs(x+dx[ma[t]],y+dy[ma[t]],d+1);
40 }
41 
42 int main()
43 {
44  //   freopen("in.txt","r",stdin);
45     int i,j;
46     ma['N']=0,ma['E']=1,ma['S']=2,ma['W']=3;
47     while(~scanf("%d%d%d",&n,&m,&s) && n)
48     {
49         for(i=0;i<n;i++)
50             scanf("%s",map[i]);
51 
52         if(dfs(0,s-1,0))printf("%d step(s) to exit\n",ans1);
53         else printf("%d step(s) before a loop of %d step(s)\n",ans1,ans2);
54     }
55     return 0;
56 }

 

转载于:https://www.cnblogs.com/zhsl/archive/2012/12/27/2834975.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值