equipy_rrt @ 2024-11-02 18:53:48
#include<cstdio>
using namespace std;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
struct data{
int n,m,k,x,y,d,tot;
char g[1005][1005];
bool f[1005][1005];
}s[7];
int main(){
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++){
scanf("%d %d %d",&s[i].n,&s[i].m,&s[i].k);
scanf("%d %d %d",&s[i].x,&s[i].y,&s[i].d);
s[i].tot=s[i].f[s[i].x][s[i].y]=1;
for(int j=1;j<=s[i].n;j++)
for(int o=1;o<=s[i].m;o++)
scanf("%c",&s[i].g[j][o]);
}
for(int i=1;i<=t;i++)
for(int j=1;j<=s[i].k;j++){
int nx=s[i].x+dx[s[i].d],ny=s[i].y+dy[s[i].d];
if(s[i].g[nx][ny]=='.' && nx>=1 && nx<=s[i].n && ny>=1 && ny<=s[i].m){
s[i].x+=dx[s[i].d],s[i].y+=dy[s[i].d];
if(!s[i].f[nx][ny]) s[i].tot++;
s[i].f[nx][ny]=1;
}
else s[i].d=(s[i].d+1)%4;
}
for(int i=1;i<=t;i++) printf("%d\n",s[i].tot);
return 0;
}