赛时40分,现在还不知道错哪里了
查看原帖
赛时40分,现在还不知道错哪里了
1121929
2023nsty04楼主2025/1/27 11:54

40分,求看代码。

#include<bits/stdc++.h>
using namespace std;
int t,xx[]={0,1,0,-1},yy[]={1,0,-1,0},ans=1,n,m,k;
char a[1010][1010];
bool f=0;
bool check(int x,int y)
{
	if(x>n||x<1||y>m||y<1)return 0;
	if(a[x][y]=='x')return 0;
	else return 1;
}
void dfs(int x,int y,int d)
{
	if(k<=0||f==1)
	{
		f=1;
		return;
	}
	k--;
	int nx=x+xx[d],ny=y+yy[d];
	if(check(nx,ny))
	{
		ans++;
		dfs(nx,ny,d);
	}
	else dfs(x,y,(d+1)%4);
} 
int main()
{
	//freopen("explore.in","r",stdin);
	//freopen("explore.out","w",stdout);
	cin>>t;
	while(t--)
	{
		memset(a,0,sizeof(a));
		int x,y,d;
		cin>>n>>m>>k>>x>>y>>d;
		for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>a[i][j];
		f=0;
		dfs(x,y,d);
		cout<<ans<<endl;
		ans=1;
	}
	return 0;
}//赛时
2025/1/27 11:54
加载中...