#include<iostream> using namespace std; const int maxn=100+10; const int dx[]={-1,0,1,0}; const int dy[]={0,1,0,-1}; int B[maxn][maxn]={0}; bool pass[maxn][maxn]={0}; int Pass(int x, int y) { int ans =B[x][y]; if(pass[x][y]) ans/=2; pass[x][y]=true; return ans; } int value(int x, int y,int d) { int ans = 0; switch(d) { case 0:ans=Pass(x-1,y-1)+Pass(x-1,y);break; case 1:ans=Pass(x-1,y)+Pass(x,y);break; case 2:ans=Pass(x,y-1)+Pass(x,y);break; case 3:ans=Pass(x-1,y-1)+Pass(x,y-1);break; } return ans; } int main() { int n,m; cin>>n>>m; for(int i = 1; i<=n; i++) for(int j=1;j<=m ;j++) { char t;cin>>t; B[i][j]=t-'0'; } int x =1, y=1, ans=0,d=1; char t; while(cin>>t) { if(t=='#')break; switch(t) { case'M': ans+=value(x,y,d); x +=dx[d];y+=dy[d];break; case'L': d--;if(d<0) d=3;break; case'R': d++;if(d>3) d=0;break; } } cout<<ans<<endl; return 0; }
http://acm.sgu.ru/problem.php?contest=0&problem=463,以每个block左上顶点为参考计算坐标。。