社区讨论

0分全RE求条

B3625迷宫寻路参与者 3已保存回复 5

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
5 条
当前快照
1 份
快照标识符
@mhj2wecm
此快照首次捕获于
2025/11/03 19:50
4 个月前
此快照最后确认于
2025/11/03 19:50
4 个月前
查看原帖
石山代码,求条
CPP
#include<iostream>
#include<queue>
#include<string.h>
using namespace std;
int n,m;
int dx[5]={0,0,1,0,-1};
int dy[5]={0,1,0,-1,0};
bool can=false;
bool a[105][105];
string s;
queue<int> x;
queue<int> y;
void tiaoshi()
{
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cout<<a[i][j];
		}
		cout<<endl;
	}
}
void bfs(int j,int i)
{
	if(a[i][j]==true||i>n||j>m)
		return;
	if(i==n&&j==m)
	{
		can=true;
		return;
	}
	a[i][j]=true;
	for(int k=1;k<=4;k++)
	{
		x.push(j+dx[k]);
		y.push(i+dy[k]);
	}
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		for(int j=1;j<=m;j++)
		{
			a[i][j]=(s[j-1]=='#'?true:false);
		}
	}
	tiaoshi();
		x.push(1);
		y.push(1);
		while(!x.empty())
		{
			bfs(x.front(),y.front());
			x.pop();
			y.pop(); 
			cout<<endl;
			tiaoshi();
			if(can)
			{
				cout<<"Yes";
				return 0;
			}
		}
	cout<<"NO";
}

回复

5 条回复,欢迎继续交流。

正在加载回复...