sgu 463 - Walking around Berhattan

在Berhattan街区中,行人沿着街道和大道行走,每经过一个街区,满意度根据街区美观程度变化。本篇介绍了一个算法,用于计算行人完成特定路径后的总满意度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

内容概要:本文档提供了关于“微型车间生产线的设计与生产数据采集试验研究”的毕业设计复现代码,涵盖从论文结构生成、机械结构设计、PLC控制系统设计、生产数据采集与分析系统、有限元分析、进度管理、文献管理和论文排版系统的完整实现。通过Python代码和API调用,详细展示了各个模块的功能实现和相互协作。例如,利用SolidWorks API设计机械结构,通过PLC控制系统模拟生产流程,使用数据分析工具进行生产数据的采集和异常检测,以及利用进度管理系统规划项目时间表。 适合人群:具有机械工程、自动化控制或计算机编程基础的学生或研究人员,尤其是从事智能制造领域相关工作的人员。 使用场景及目标:①帮助学生或研究人员快速搭建和理解微型车间生产线的设计与实现;②提供完整的代码框架,便于修改和扩展以适应不同的应用场景;③作为教学或科研项目的参考资料,用于学习和研究智能制造技术。 阅读建议:此资源不仅包含详细的代码实现,还涉及多个学科领域的知识,如机械设计、电气控制、数据分析等。因此,在学习过程中,建议读者结合实际操作,逐步理解每个模块的功能和原理,并尝试调整参数以观察不同设置下的系统表现。同时,可以参考提供的文献资料,深入研究相关理论和技术背景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值