40pts求调
查看原帖
40pts求调
1500582
xuhy3577楼主2025/1/17 13:11
#include<bits/stdc++.h>
using namespace std;

char a[1009][1009];
int t,cnt=0;
int n,m,k;
int x,y,d;
int main()
{
	cin>>t;
	while(t--)
	{
		cnt=1;
		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];
		for(int i=1;i<=k;i++)
		{
		    d%=4;
			if(d==0)
			{
				if(x<=n&&y+1<=m&&a[x][y+1]=='.') 
				{
					cnt++;
					y=y+1;
				}
				else d++;
			}
			else if(d==1)
			{
				if(x+1<=n&&y<=m&&a[x+1][y]=='.') 
				{
					cnt++;
					x=x+1;
				}
				else d++;
			}
			else if(d==2)
			{
				if(x<=n&&y-1>=1&&a[x][y-1]=='.') 
				{
					cnt++;
					y=y-1;
				}
				else d++;
			}
			else if(d==3)
			{
				if(x-1>=1 &&y<=m&&a[x-1][y]=='.') 
				{
					cnt++;
					x=x-1;
				}
				else d++;
			}
		}
		cout<<cnt<<endl;
	}
	
	return 0;
}
2025/1/17 13:11
加载中...