0分问号?
查看原帖
0分问号?
1093380
zhangfengkai001楼主2024/7/9 16:10
#include<bits/stdc++.h>
using namespace std;

int X,Y;
int n,m;
char s[1500][1500];
bool b[1500][1500];
bool ttf=0;

inline int vbs(int a,int b)
{
	return (abs(a)+b)%b;
}

inline bool tf(int x,int y)
{
	return b[vbs(x,n)][vbs(y,m)];
}

void Dfs(int x,int y)
{
	if(tf(x,y))
	{
		if(x!=X && y!=Y && vbs(x,n)==X && vbs(y,m)==Y)
		{
			ttf=1;
			return;
		}
		b[vbs(x,n)+1][vbs(y,m)]=0;Dfs(vbs(x,n)+1,vbs(y,m));b[vbs(x,n)+1][vbs(y,m)]=1;
		if(ttf) return; 
		b[vbs(x,n)-1][vbs(y,m)]=0;Dfs(vbs(x,n)-1,vbs(y,m));b[vbs(x,n)-1][vbs(y,m)]=1;
		if(ttf) return; 
		b[vbs(x,n)][vbs(y,m)+1]=0;Dfs(vbs(x,n),vbs(y,m)+1);b[vbs(x,n)][vbs(y,m)+1]=1;
		if(ttf) return; 
		b[vbs(x,n)][vbs(y,m)-1]=0;Dfs(vbs(x,n),vbs(y,m)-1);b[vbs(x,n)][vbs(y,m)-1]=1;
	}
	return;
}

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	while(cin>>n>>m)
	{
		ttf=0;
		memset(b,1,sizeof(b));
		for(int i=0;i<n;i++)
		{
			cin>>s[i];
			for(int j=0;j<m;j++)
			{
				if(s[i][j]=='S')
				{
					X=i,Y=j;
				}
				if(s[i][j]=='#')
				{
					b[i][j]=false;
				}
			}
		}
		if(ttf)
		{
			cout<<"Yes\n";
		}
		else
		{
			cout<<"No\n";
		}
	}
	return 0;
}

只输出“No”。

2024/7/9 16:10
加载中...