#include<stdio.h>
#include<string.h>
#define MAXN int(1e3+5)
bool path[MAXN][MAXN];
int n,m,k,x,y,d,t,it[2][4]={0,1,1,0,0,-1,-1,0},cnt;
void cin()
{
	cnt=0;
	memset(path,0,sizeof(path));
	scanf("%d%d%d%d%d%d",&n,&m,&k,&x,&y,&d);
	char temp;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
		{
			scanf("%d",temp);
			path[i][j]=temp=='.';
		}
}
void Just_Do_It()
{
	x+=it[0][d];
	y+=it[1][d];
	cnt++;
	if(x<1||y<1||x>m||y>m)
	{
		x-=it[0][d];
		y-=it[1][d];
		d=(d+1)%4;
		cnt--;
	}
}
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		cin();
		while(k--)
			Just_Do_It();
		printf("%d\n",cnt);
	}
	return 0;
}

1 comments

  • 1

Information

ID
542
Time
1000ms
Memory
256MiB
Difficulty
7
Tags
# Submissions
596
Accepted
157
Uploaded By