//\\__ hr1212 __//\\
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
int n,m,cnt,id,l;
char a[2000][2000],p[MAX];
vector<char> v;
map<char,int> mm;
void solve(int x,int y,char dir){
id++;
if(a[x][y]=='*'){
cnt++;
a[x][y]='.';
}
if(id==l){
pi(cnt);
}
else if(p[id]=='D'){
solve(x,y,v[(mm[dir]+1)%4]);
}
else if(p[id]=='E'){
solve(x,y,v[(mm[dir]-1+4)%4]);
}
else{
int p=x,q=y;
if(dir=='N')
p=p-1;
if(dir=='L')
q=q+1;
if(dir=='S')
p=p+1;
if(dir=='O')
q=q-1;
if(p<0 || p>=n || q<0 || q>=m || a[p][q]=='#')
solve(x,y,dir);
else
solve(p,q,dir);
}
}
int main(){
int r,k,i,c=0,x=0,y=0,j,t,z,x1=0,y1=0;
ll ans=0;
char dir;
mm['N']=0;mm['L']=1;mm['S']=2;mm['O']=3;
v.pb('N');v.pb('L');v.pb('S');v.pb('O');
while(1){
siii(n,m,l);
if(n==0 && m==0 && l==0)
break;
f(i,0,n){
scanf("%s",a[i]);
f(j,0,m){
if(a[i][j]=='N' || a[i][j]=='S' || a[i][j]=='L' || a[i][j]=='O'){
x=i;y=j;dir=a[i][j];
}
}
}
scanf("%s",p);
id=-1;cnt=0;
solve(x,y,dir);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
int n,m,cnt,id,l;
char a[2000][2000],p[MAX];
vector<char> v;
map<char,int> mm;
void solve(int x,int y,char dir){
id++;
if(a[x][y]=='*'){
cnt++;
a[x][y]='.';
}
if(id==l){
pi(cnt);
}
else if(p[id]=='D'){
solve(x,y,v[(mm[dir]+1)%4]);
}
else if(p[id]=='E'){
solve(x,y,v[(mm[dir]-1+4)%4]);
}
else{
int p=x,q=y;
if(dir=='N')
p=p-1;
if(dir=='L')
q=q+1;
if(dir=='S')
p=p+1;
if(dir=='O')
q=q-1;
if(p<0 || p>=n || q<0 || q>=m || a[p][q]=='#')
solve(x,y,dir);
else
solve(p,q,dir);
}
}
int main(){
int r,k,i,c=0,x=0,y=0,j,t,z,x1=0,y1=0;
ll ans=0;
char dir;
mm['N']=0;mm['L']=1;mm['S']=2;mm['O']=3;
v.pb('N');v.pb('L');v.pb('S');v.pb('O');
while(1){
siii(n,m,l);
if(n==0 && m==0 && l==0)
break;
f(i,0,n){
scanf("%s",a[i]);
f(j,0,m){
if(a[i][j]=='N' || a[i][j]=='S' || a[i][j]=='L' || a[i][j]=='O'){
x=i;y=j;dir=a[i][j];
}
}
}
scanf("%s",p);
id=-1;cnt=0;
solve(x,y,dir);
}
return 0;
}
No comments:
Post a Comment