sgu 463 - Walking around Berhattan

K - Walking around Berhattan
Time Limit:250MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit  Status  Practice  SGU 463

Description

As you probably know, Berhattan is a district of Berland's largest city and it consists of equal square blocks. There are  n block lines in the east-west direction and  m block lines in the south-north direction. The map shows Berhattan as a rectangle with  n rows and  mcolumns, so there are  nm blocks in total. 

There are  n+1 streets running parallel in the east-west direction (horizontally), and there are  m+1 avenues running parallel in the south-north direction (vertically). Streets and avenues split the district into blocks and separate Berhattan from other districts of Berland. Each block in Berhattan is characterized by its beauty  b ij

A pedestrian can walk only along streets and avenues. When the pedestrian walks along any of four sides of a block, we say he passes the block. Every time the pedestrian passes a block his satisfaction is increased by  b ij. If the pedestrian has already passed the block one or more times his satisfaction is increased only by  b ij/2 rounded down when he passes the block again. 

You are given the map of Berhattan with the information about the blocks' beauty and the pedestrian's path along the streets and avenues. The path is given as a string containing letters ' 
L
', ' 
R
' and ' 
M
', where ' 
L
' means a 90 degree left turn, ' 
R
' means a 90 degree right turn, and ' 
M
' means walking one block forward by a street or avenue. Facing the east, the pedestrian starts his path in the north-west corner of Berhattan having zero satisfaction level. His path can cross itself and go along the same streets or avenues several times. Pedestrian's satisfaction is increased every time he moves according to the rules described above. 

Your task is to calculate the total satisfaction the pedestrian will get after finishing his route. 


Picture of the sample test

Input

The first line of input contains two integers  n and  m (1 ≤  nm ≤ 100), where  n is a number of block lines in Berhattan running in the east-west direction, and  m is a number of block lines in Berhattan running in the south-north direction. The following  n lines contain  m digits each. The  j-th digit of the  i-th line represents  b ij (0 ≤  b ij ≤ 9) — the beauty of the corresponding block. The last line of input contains a path in the format specified above. The path consists of 1 up to 500 characters, inclusively. It is guaranteed that the given path doesn't go outside Berhattan.

Output

Print a single integer to the output — the total pedestrian's satisfaction.

Sample Input

sample input
sample output
3 3
123
456
789
MRMMLM
22

 

 

简单模拟,n,m貌似给反了(两个地方给的不一致 )  害我wa了两发

  1 /*************************************************************************
  2     > File Name: code/2015summer/#5/K.cpp
  3     > Author: 111qqz
  4     > Email: rkz2013@126.com 
  5     > Created Time: 2015年07月30日 星期四 14时00分56秒
  6  ************************************************************************/
  7 
  8 #include<iostream>
  9 #include<iomanip>
 10 #include<cstdio>
 11 #include<algorithm>
 12 #include<cmath>
 13 #include<cstring>
 14 #include<string>
 15 #include<map>
 16 #include<set>
 17 #include<queue>
 18 #include<vector>
 19 #include<stack>
 20 #define y0 abc111qqz
 21 #define y1 hust111qqz
 22 #define yn hez111qqz
 23 #define j1 cute111qqz
 24 #define tm crazy111qqz
 25 #define lr dying111qqz
 26 using namespace std;
 27 #define REP(i, n) for (int i=0;i<int(n);++i)  
 28 typedef long long LL;
 29 typedef unsigned long long ULL;
 30 const int inf = 0x7fffffff;
 31 const int N=1e2+5;
 32 int b[N][N];
 33 int n,m;
 34 char cmd[505];
 35 bool vis[N][N];
 36 int nx,ny;
 37 int dx[4]={-1,0,1,0};
 38 int dy[4]={0,1,-0,-1};
 39 char ch[N][N];
 40 int main()
 41 {
 42     cin>>n>>m;
 43     nx = 0;
 44     ny = 0;
 45     for ( int i = 0 ; i < n ; i++)
 46     cin>>ch[i];
 47     for ( int i = 0 ; i <n ; i++ )
 48     {
 49     for ( int j = 0 ; j < m ; j++ )
 50     {
 51         b[i+1][j+1]=(int)(ch[i][j]-'0');
 52     }
 53     }
 54     int ans  = 0;
 55     memset(vis,false,sizeof(vis));
 56     int dir = 1;
 57     cin>>cmd;
 58     int len = strlen(cmd);
 59     for ( int i = 0 ;  i < len ; i ++ )
 60     {
 61 //    cout<<"ans:"<<ans<<endl;
 62 //    cout<<"nx:"<<nx<<" ny:"<<ny<<endl;
 63     if (cmd[i]=='L')
 64     {
 65         dir = (dir+3)%4;
 66     }
 67     if (cmd[i]=='R')
 68     {
 69         dir  = (dir+1)%4;
 70     }
 71     if (cmd[i]=='M')
 72     {
 73         if (dir==0)
 74         {
 75         if (vis[nx][ny])
 76         {
 77             ans = ans + b[nx][ny]/2;
 78         }
 79         else
 80         {
 81             ans = ans + b[nx][ny];
 82         }
 83         if (vis[nx][ny+1])
 84         {
 85             ans = ans + b[nx][ny+1]/2;
 86         }
 87         else
 88         {
 89             ans = ans + b[nx][ny+1];
 90         }
 91         vis[nx][ny]=true;
 92         vis[nx][ny+1]=true;
 93         nx = nx +dx[dir];
 94         ny = ny +dy[dir];
 95         }
 96         if (dir==2)
 97         {
 98         nx = nx + dx[dir];
 99         ny = ny + dy[dir];
100         if (vis[nx][ny])
101         {
102             ans = ans + b[nx][ny]/2;
103         }
104         else
105         {
106             ans = ans + b[nx][ny];
107         }
108         if (vis[nx][ny+1])
109         {
110             ans = ans + b[nx][ny+1]/2;
111         }
112         else
113         {
114             ans = ans + b[nx][ny+1];
115         }
116         vis[nx][ny]=true;
117         vis[nx][ny+1]=true;
118         }
119         if (dir==1)
120         {
121         nx = nx + dx[dir];
122         ny = ny + dy[dir];
123         if (vis[nx][ny])
124         {
125             ans = ans + b[nx][ny]/2;
126         }
127         else
128         {
129             ans = ans + b[nx][ny];
130         }
131         if (vis[nx+1][ny])
132         {
133             ans = ans + b[nx+1][ny]/2;
134         }
135         else
136         {
137             ans = ans + b[nx+1][ny];
138         }
139         vis[nx][ny]=true;
140         vis[nx+1][ny]=true;
141         
142         }
143             if (dir==3)
144         {
145         
146         if (vis[nx][ny])
147         {
148             ans = ans + b[nx][ny]/2;
149         }
150         else
151         {
152             ans = ans + b[nx][ny];
153         }
154         if (vis[nx+1][ny])
155         {
156             ans = ans + b[nx+1][ny]/2;
157         }
158         else
159         {
160             ans = ans + b[nx+1][ny];
161         }
162         vis[nx][ny]=true;
163         vis[nx+1][ny]=true;
164         nx = nx +dx[dir];
165         ny = ny +dy[dir];
166         }
167     }
168 
169     }
170     cout<<ans<<endl;
171   
172     return 0;
173 }

 

 

 

转载于:https://www.cnblogs.com/111qqz/p/4690440.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值