思路
暴力枚举每一个点,对于每一个点,按照输入指令进行操作,如果移动过程中始终没有到达墙(即 # 中),就将答案加 ,最后输出答案即可。
Code
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const int E = 1e6 + 5;
ll h, w, n;
char a[1001][1001], op[E];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> h >> w >> n;
cin >> op;
for (int i = 1; i <= h; i++)
for (int j = 1; j <= w; j++)
cin >> a[i][j];
ll ans = 0;
for (int i = 1; i <= h; i++)
for (int j = 1; j <= w; j++)
{
if (a[i][j] == '#')
continue;
ll x = i, y = j;
bool flag = 1;
for (int i = 0; i < n; i++)
{
if (op[i] == 'L')
y--;
if (op[i] == 'R')
y++;
if (op[i] == 'U')
x--;
if (op[i] == 'D')
x++;
if (x < 1 || x > h || y < 1 || y > w || a[x][y] == '#')
flag = false;
}
if (flag)
ans++;
}
cout << ans;
return 0;
}