AcWing 6039. 地图探险
原题链接
简单
作者:
魔仙哥
,
2024-12-20 14:22:50
,
所有人可见
,
阅读 1
#include<bits/stdc++.h>
using namespace std;
const int N = 1005;
#define LL long long
#define F(i,a,b) for(int i=a;i<=b;i++)
int T,n,m,k,x,y,d,nx,ny;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
char a[N][N];
bool vis[N][N];
int main()
{
cin>>T;
while(T--)
{
cin>>n>>m>>k>>x>>y>>d;
memset(vis,0,sizeof vis);
for(int i = 1;i<=n;i++)
for(int j = 1;j<=m;j++)
cin>>a[i][j];
vis[x][y] = 1;
while(k--)
{
nx = x+dx[d],ny = y+dy[d];
if(nx >= 1 && nx <= n && ny >= 1 && ny <= m && a[nx][ny] == '.')
{
x = nx,y = ny;
vis[x][y] = 1;
}
else d = (d+1)%4;
}
int ans = 0;
for(int i = 1;i<=n;i++)
for(int j = 1;j<=m;j++)
ans += vis[i][j];
cout<<ans<<'\n';
}
return 0;
}