跳到正文

个人记录

efdsgdsgfdghd

Tommyy约 3 分钟
原文

这是 2026年6月12日 存档的第 3 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年5月10日
收录
2026年5月10日
更新
2026年11月12日
篇幅
约 3 分钟

版本

  1. v4当前
  2. v3
  3. v2
  4. v1
C++
#include<bits/stdc++.h>
using namespace std;
int n,m,vis[10][100050];
char a[10][100050];
struct Node
{
	int x,y,shuimian;
};
queue<Node>q;
void bfs(int ex,int ey)
{
	q.push({ex,ey,0});
	vis[ex][ey]=1;
	while(q.size()>0)
	{
		Node now=q.front();
		q.pop();
		//cout<<now.x<<' '<<now.y<<'\n';
		if(now.y>=n)
		{
			cout<<"YES";
			exit(0);
		}
		if(now.y<=now.shuimian)
		{
			continue;
		}
		if(now.x==1)
		{
			if(now.y-1>=1 and vis[now.x][now.y-1]==0 and a[now.x][now.y-1]!='X')
			{
				q.push({now.x,now.y-1,now.shuimian+1});
				vis[now.x][now.y-1]=1;
			}
			if(vis[now.x][now.y+1]==0 and a[now.x][now.y+1]!='X')
			{
				q.push({now.x,now.y+1,now.shuimian+1});
				vis[now.x][now.y+1]=1;
			}
			if(vis[2][now.y+m]==0 and a[2][now.y+m]!='X')
			{
				q.push({2,now.y+m,now.shuimian+1});
				vis[2][now.y+m]=1;
			}
		}
		else
		{
			if(now.y-1>=1 and vis[now.x][now.y-1]==0 and a[now.x][now.y-1]!='X')
			{
				q.push({now.x,now.y-1,now.shuimian+1});
				vis[now.x][now.y-1]=1;
			}
			if(vis[now.x][now.y+1]==0 and a[now.x][now.y+1]!='X')
			{
				q.push({now.x,now.y+1,now.shuimian+1});
				vis[now.x][now.y+1]=1;
			}
			if(vis[1][now.y+m]==0 and a[1][now.y+m]!='X')
			{
				q.push({1,now.y+m,now.shuimian+1});
				vis[1][now.y+m]=1;
			}
		}
	}
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=2;i++){
		for(int j=1;j<=n;j++){
			cin>>a[i][j];
		} 
	}
	bfs(1,1);
	cout<<"NO";
	return 0;
}
/*
--X-X-
X--XX-
	
X-
--
-X
X-
XX
--
*/