VelvetChords @ 2024-10-28 13:47:15
#include<bits/stdc++.h>
using namespace std;
int T,n,m,k,x,y,d;
char a[1005][1005];
bool f[1005][1005];
int main(){
cin>>T;
while(T--)
{
cin>>n>>m>>k>>x>>y>>d;
long long ans=0;
memset(f,0,sizeof f);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>a[i][j];
for(int i=1;i<=k;i++)
{
f[x][y]=1;
if(d==0)
{
if(a[x][y+1]=='.') y++;
else if(a[x+1][y]=='.') d=1;
else if(a[x][y-1]=='.') d=2;
else if(a[x-1][y]=='.') d=3;
}
else if(d==1)
{
if(a[x+1][y]=='.') x++;
else if(a[x][y-1]=='.') d=2;
else if(a[x-1][y]=='.') d=3;
else if(a[x][y+1]=='.') d=0;
}
else if(d==2)
{
if(a[x][y-1]=='.') y--;
else if(a[x-1][y]=='.') d=3;
else if(a[x][y+1]=='.') d=0;
else if(a[x+1][y]=='.') d=1;
}
else if(d==3)
{
if(a[x-1][y]=='.') x--;
else if(a[x][y+1]=='.') d=0;
else if(a[x+1][y]=='.') d=1;
else if(a[x][y-1]=='.') d=2;
}
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(f[i][j]==1) ans++;
cout<<ans<<endl;
}
return 0;
}
by PeacefulStagnation @ 2024-10-28 16:51:07
@tangchenhui 其实不一定要清空a数组,直接判断边界也是可以的(当然清空数组也可以正确)