6

噢莫加纳加加加  •  22小时前


#include<bits/stdc++.h>
using namespace std;
char a[10005][10005];
bool s[10005][10005];
int main(){
	int t;
	cin>>t;
	while(t--){
		int x,y,n,m,k,d;
		cin>>n>>m>>k;
		cin>>x>>y>>d;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				cin>>a[i][j];
			}
		}
		memset(s,false,sizeof(s));
		int cnt=1;
		s[x][y]=true;
		for(int i=1;i<=k;i++){
			if(d==0&&y+1<=m&&a[x][y+1]=='.')
				y++;
			else if(d==1&&x+1<=n&&a[x+1][y]=='.')
				x++;
			else if(d==2&&y-1>=1&&a[x][y-1]=='.')
				y--;
			else if(d==3&&x-1>=1&&a[x-1][y]=='.')
				x--;
			else
				d=(d+1)%4;	
			if(!s[x][y])
				cnt++;
			s[x][y] = true;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

评论:

请先登录,才能进行评论