Start: Jun, 05, 2019 13:00:00
2019春ACM通识课考试(第一场)
End: Jun, 05, 2019 16:00:00
Time elapsed:
Time remaining:

Problem_ID: G
Result: Accepted
Time: 48ms
Memory: 1728kB
Author: 2017212212292
In contest: 1269

#include<iostream>
#include<string>
#include<cstring>
#include<map>
using namespace std;
const int inf=0x3f3f3f3f;
map<string,int>mp;
int movx[8]={0,0,-1,1,-1,1,-1,1},
	movy[8]={1,-1,0,0,1,1,-1,-1};
void ini()
{
	mp["R"]=0;
	mp["L"]=1;
	mp["U"]=2;
	mp["D"]=3;
	mp["RU"]=4;
	mp["RD"]=5;
	mp["LU"]=6;
	mp["LD"]=7;
}
int main()
{
	int t;
	string s[110];
	int ma[110][110];
	ini();
	cin>>t;
	while(t--)
	{
		int m,n;
		cin>>n>>m;
		for(int i=0;i<n;i++)
		{
			cin>>s[i];
			for(int j=0;j<m;j++)
			{
				if(s[i][j]=='#')
					ma[i][j]=inf;
				else
					ma[i][j]=s[i][j]-'0';
			}
		}
		string movt;
		int x,y,w,nx,ny,flg=0;
		cin>>x>>y>>w;
		nx=x;
		ny=y;
		cin>>movt;
		while(nx>=0&&nx<n&&ny>=0&&ny<m)
		{
			if(s[nx][ny]=='#'&&(nx!=x||ny!=y))
				break;
			else if(ma[nx][ny]<w)
			{
				flg=1;
				break;
			}
			nx+=movx[mp[movt]];
			ny+=movy[mp[movt]];
		}
		cout<<flg<<endl;
	}
}