Homework Introduction
知识点:
- Status
- Done
- Problem
- 5
- Open Since
- 2024-12-15 0:00
- Deadline
- 2024-12-23 23:59
- Extension
- 24 hour(s)
知识点:
BFS使用队列(queue)来实施算法过程,队列(queue)有着先进先出FIFO(First Input First Output)的特性,BFS操作步骤如下:
1、把起始点放入queue;
2、重复下述2步骤,直到queue为空为止:
1) 从queue中取出队列头的点;
2) 找出与此点邻接的且尚未遍历的点,进行标记,然后全部放入queue中。
结构一:求一个解、所有解、最优解(数组模拟)
head=0;
tail=1;
while head<tail
{
if 找到目标状态
then 做相应处理(退出循环输出解、输出当前解、比较解的优劣)
else
{ 扩展头节点;
if 结点拓展出的新节点没出现过 then
{
tail++
将新节点添加入队列;
}
}
head++
}
结构二:找到一个解就退出(或者无解)
p=true;
while (p)
{
if 头结点是目标状态 then p=false
else {
扩展头节点
if 头结点拓展出的新节点没出现过 then
{
tail++;
将新节点添加入队列;
}
head++
if head>tail then p=false;
}
}
By signing up a QinCai--OJ universal account, you can submit code and join discussions in all online judging services provided by us.