跳到正文

个人记录

最短路总结

the133lvlone约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年10月6日
收录
2026年1月3日
更新
2026年11月11日
篇幅
约 1 分钟

版本

  1. v1当前

总结

T1

C++
struct B
{
	int x,y,z;
	bool b;
}
int d=0x1602;
bool e[1602][1602];
char m[1602][1602];
int A(queue<B>a)
{
	memset(e,true,sizeof(e));
	if(m[a.front().x][a.front().y]=='*')
	{
		return 0x1602;
	}
	e[a.front().x][a.front().y]=false;
	while(a.size())
	{
		B k=a.front();
		a.pop();
		if(m[k.x][k.y]=='A')
		{
			for(int i=0;i<4;i++)
			{
				if(k.x+p[i])
				if(E(k.x+p[i],k.y+q[i]))
				{
					a.push({k.x+p[i],k.y+q[i]});
				}
			}
		}
	}
	return 0x1602;
}
string D()
{
	queue<B>a;
	a.push({1,n,1});
	d=A(a);
	a.pop();
	a.push({1,1,1});
	d=min(A(a),d);
	a.pop();
	a.push({n,1,1});
	d=min(A(a),d);
	if(d==0x1602)
	{
		return "No answer";
	}
	return to_string(d);
}
代码
bfs遇到障碍不去,走两步的=走一步*2,斜着走额外开个位移数组或者选择在不同直线上的方向走2步,聚气分2步走
原文