80WA求调
查看原帖
80WA求调
884905
shenqing_QAQ楼主2024/11/4 21:50

玄2关

#include<bits/stdc++.h>
using namespace std;
const int N=1005;
int T,n,m,k;
int sx,sy,sd,ans;
char a[N][N];
bool vis[N][N][4];
const int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
struct node
{
	int x,y,d,step;
};
queue<node> q;
void bfs()
{
	while(!q.empty()) q.pop();
	vis[sx][sy][sd]=1;
	q.push((node){sx,sy,sd,0});
	while(!q.empty())
	{
		node now=q.front();
		q.pop();
		if(now.step==k) return;
		int xx=now.x+dx[now.d],yy=now.y+dy[now.d];
		if(vis[xx][yy][now.d]) return;
		if(a[xx][yy]!='x'&&xx>0&&xx<=n&&yy>0&&yy<=m)
		{
			ans+=!(vis[xx][yy][0]||vis[xx][yy][1]||vis[xx][yy][2]||vis[xx][yy][3]);
			vis[xx][yy][now.d]=1;
			q.push((node){xx,yy,now.d,now.step+1});
		}
		else
		{
			xx=now.x,yy=now.y;
			int dd=(now.d+1)%4;
			if(vis[xx][yy][dd]) return;
			vis[xx][yy][dd]=1;
			q.push((node){xx,yy,dd,now.step+1});
		}
	}
	return;
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>T;
	while(T--)
	{
		cin>>n>>m>>k>>sx>>sy>>sd;
		ans=1;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				cin>>a[i][j],vis[i][j][0]=vis[i][j][1]=vis[i][j][2]=vis[i][j][3]=0;
		bfs();
		cout<<ans<<endl;
	}
	return 0;
}
2024/11/4 21:50
加载中...