作业介绍
广搜模板
int n,m;//一般输入的行列数/边界
struct node{
int x, y, s;
};//保存点的信息
int dx[]={};//x方向
int dy[]={};//y方向
int vis[n][m],mapp[N][N];//vis初始化应该在主函数
int BFS(int x,int y)
{
//起点特判,也可以在主函数中特判
if(x == endx && y == endy)//满足条件
{
return 1;
}
queue<node> q;
q.push({x, y, 1});//将起始点先放进队列
vis[x][y] = 1;//标记起始点
while(!q.empty())//队列非空表示有路径可搜
{
int tx = q.front().x;
int ty = q.front().y;
int ts = q.front().s;//取出队首的点
q.pop();//将队首抛弃
for()
{
int xx = tx + dx[];
int yy = ty + dy[];
if(xx == endx && yy == endy)//满足条件
{
return ts + 1;
}
//判断是否在边界内,是否不可搜索,是否曾搜索过
if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&!vis[xx][yy])
{
vis[xx][yy] = 1;
q.push({xx, yy, ts + 1});//将新的可搜点放进队列
}
}
}
return -1;//如果搜不到
}
- 状态
- 已结束
- 题目
- 12
- 开始时间
- 2025-1-9 0:00
- 截止时间
- 2025-1-16 23:59
- 可延期
- 24 小时