标签:
Description
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.
Input
Output
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 }
sgu 463 - Walking around Berhattan
标签:
原文地址:http://www.cnblogs.com/111qqz/p/4690440.html