蒟蒻30pts求救
查看原帖
蒟蒻30pts求救
304394
虹雷Arkhalis楼主2024/10/29 16:24

调了好长时间bug还是没找出来,样例都过不了,混了3个点(悲

#include <bits/stdc++.h>
using namespace std;

const int mx=1e3+9;
char s[mx][mx];
int t;
bool sqa[mx][mx];
long long ans;
int n,m,k,x,y,d;

void tb()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

void jc()
{
	if(sqa[x][y]==0)
	{
		sqa[x][y]=1;
		ans++;
	}
}

void solve()
{
	if(d==0)
	{
		if(s[x][y+1]=='.'&&y<m)
		{
			y++;
			jc();
		}
		else
			d=(d+1)%4;
	}
	else if(d==1)
	{
		if(s[x+1][y]=='.'&&x<n)
		{
			x++;
			jc();
		}
		else
			d=(d+1)%4;
	}
	else if(d==2)
	{
		if(s[x][y-1]=='.'&&y>1)
		{
			y--;
			jc();
		}
		else
			d=(d+1)%4;
	}
	else if(d==3)
	{
		if(s[x-1][y]=='.'&&x>1)
		{
			x--;
			jc();
		}
		else
			d=(d+1)%4;
	}
}

int main()
{
	memset(sqa,0,sizeof(sqa)); 
	tb();
	cin>>t;
	while(t--)
	{
		ans=1;
		cin>>n>>m>>k;
		cin>>x>>y>>d;
		sqa[x][y]=1;
		for(int i=1;i<=n;++i)
			for(int j=1;j<=m;++j)
				cin>>s[i][j];
		while(k--)
			solve();
		cout<<ans<<endl;
	}
	return 0;
}
2024/10/29 16:24
加载中...