当前位置: 首页 > news >正文

wap建站系统网站维护一般都是维护什么

wap建站系统,网站维护一般都是维护什么,做招聘网站怎么办营业执照,微信公众号推广网站《数据结构、算法与应用C语言描述》-队列的应用-电路布线问题 问题描述 在 迷宫老鼠问题中,可以寻找从迷宫入口到迷宫出口的一条最短路径。这种在网格中寻找最短路径的算法有许多应用。例如,在电路布线问题的求解中,一个常用的方法就是在布…

《数据结构、算法与应用C++语言描述》-队列的应用-电路布线问题

问题描述

在 迷宫老鼠问题中,可以寻找从迷宫入口到迷宫出口的一条最短路径。这种在网格中寻找最短路径的算法有许多应用。例如,在电路布线问题的求解中,一个常用的方法就是在布线区域设置网格,该网格把布线区域划分成nxm个方格,就像迷宫一样(如图 9-12a 所示)。一条线路从一个方格 a 的中心点连接到另一个方格 b 的中心点,转弯处可以采用直角,如图 9-12b 所示。已经有线路经过的方格被“封锁”,成为下一条线路的障碍。我们希望用a 和 b之间的最短路径来布线,以减少信号的延迟。
在这里插入图片描述

求解策略

a和b之间的最短路径需要在两个过程中确定。一个是距离标记过程,另一个是路径标记过程。在距离标记过程中,先从位置a开始,把从a可到达的相邻方格都标记为1(表示与a相距为1),然后把从编号为1的方格可到达的相邻方格都标记为2(表示与a相距为2)。这个标记过程继续下去,直至到达b或者没有可到达的相邻方格为止。图9-13a 显示了这种搜索过程的结果,其中 a=(3,2),b=(4,6)。图中的阴影部分是被封锁的方格。

一旦到达 b,b 的编号便是 b 与 a之间的距离(在图 9-13a 中,b上的标号为 9)。距离标记过程结束之后,路径标记过程开始。从方格 b 开始,首先移动到一个其编号比b的编号小1的相邻方格上。在图9-13a中,我们从b移到方格(5,6)。接下来,从方格(5,6)移到比当前编号小 1 的相邻位置上。重复这个过程,直至到达 a 为止。在图 9-13a 的例子中,从(5,6),然后移到(6,6)、(6,5)、(6,4)、(5,4),等等。图 9-13b 给出了所得到的路径,它是(3,2)和(4,6)之间的最短路径。注意,最短路径不是唯一的,(3,2)、(3,3)、(4,3)、(5,3)、(5,4)、(6,4)、(6,5)、(6,6)、(5,6)、(4,6)是另一条最短路径。
在这里插入图片描述

代码

#include <iostream>
#include <queue>
using namespace std;/*用于存储迷宫地址的结构体*/
struct Position
{int row,  //行col;  //列Position() {}Position(int prow, int pcol):row(prow),col(pcol){}operator int() const { return row; }friend ostream& operator<<(ostream& out, const Position x){out << "(" << x.row << "," << x.col << ")";return out;}
};
/*创建二维数组*/
template <class T>
bool make2dArray(T**& x, int numberOfRows, int numberOfColumns)
{try {//行指针x = new T * [numberOfRows];//为每一行分配内存for (int i = 0; i < numberOfRows; i++)x[i] = new int[numberOfColumns];return true;}catch (bad_alloc) { return false; }
}/*遍历二维数组*/
template<class T>
void traverse2dArray(T**& x, int numberOfRows, int numberOfColumns)
{for (int i = 0; i < numberOfRows; i++){for (int j = 0; j < numberOfColumns; j++){cout.width(4);cout << x[i][j] << "  ";}cout << endl;}
}/*电路布线问题全局变量*/
int** Grid;//二维方阵
int GridSize;//方阵大小
queue<Position> path;//记录路径的队列
/*电路布线---和迷宫老鼠问题有点像*/
/*方格元素为1表示为障碍,方格元素为0表示无障碍*/
/*方格标记为2表示是起点,方格标记为大于2的整数m表示该方格距离起点m-2步*/
void inputGridQueue()//输入迷宫
{cout << "Please enter the size of Grid-Matrix:";while (!(cin >> GridSize)){cin.clear();//清空标志位while (cin.get() != '\n')//删除无效的输入continue;cout << "Please enter the size of Grid-Matrix:";}//+2的原因是为了避免在处理内部位置和边界位置时存在差别make2dArray<int>(Grid, GridSize + 2, GridSize + 2);//初始化边界位置的数值for (int i = 0; i <= GridSize + 1; i++){Grid[i][0] = 1;Grid[0][i] = 1;Grid[i][GridSize + 1] = 1;Grid[GridSize + 1][i] = 1;}//初始化迷宫for (int i = 1; i <= GridSize; i++)for (int j = 1; j <= GridSize; j++){int positionij;cout << "Please enter Grid[" << i << "," << j << "]:";while (!(cin >> positionij)){cin.clear();//清空标志位while (cin.get() != '\n')//删除无效的输入continue;cout << "Please enter Grid[" << i << "," << j << "]:";}Grid[i][j] = positionij;}cout << "The Grid = " << endl;traverse2dArray<int>(Grid, GridSize + 2, GridSize + 2);
}
bool findPathQueue(Position start,Position end)//寻找从起点到终点的最短路径,如找到返回true,如没找到则返回false
{if ((start.row == end.row) && (start.col == end.col))return true;//初始化偏移量Position offset[4];offset[0].row = 0; offset[0].col = 1;//右offset[1].row = 1; offset[1].col = 0;//下offset[2].row = 0; offset[2].col = -1;//左offset[3].row = -1; offset[3].col = 0;//上Position here = start;Grid[start.row][start.col] = 2;//标记起点为2int numOfNbrs = 4;//一个方格的相邻位置数/*标记各个方格*/queue<Position> q;//将需要标记的方格入栈qPosition nbr;//邻居方格while (true){//给相邻位置做标记for (int i = 0; i < numOfNbrs; i++){nbr.row = here.row + offset[i].row;nbr.col = here.col + offset[i].col;if (Grid[nbr.row][nbr.col] == 0)//只有方格为0时表示方格无障碍和未标记{Grid[nbr.row][nbr.col] = Grid[here.row][here.col] + 1;if ((nbr.row == end.row) && (nbr.col == end.col))break;//如果标记到终点,则标记完成q.push(nbr);//把邻居结点插入队列,以备后面标记,也就是找邻居的邻居}}if ((nbr.row == end.row) && (nbr.col == end.col))break;//如果标记到终点,则标记完成if (q.empty())return false;//没有找到终点,则不可达,返回falsehere = q.front();//取队首元素作为下一节点,以备标记其邻居节点q.pop();//删除队首节点}/*标记完成,构造路径*/int pathLength = Grid[end.row][end.col] - 2;here = end;//从终点开始回溯for (int i = pathLength - 1; i >= 0; i--){path.push(here);for (int j = 0; j < numOfNbrs; j++)//在周边寻找父节点{nbr.row = here.row + offset[j].row;nbr.col = here.col + offset[j].col;if (Grid[nbr.row][nbr.col] == i + 2)break;}here = nbr;}path.push(start);return true;
}
void outputPathQueue()//输出路径
{int i = 0;cout << "The path = ";while(!path.empty()){cout << path.front() << ", ";path.pop();}cout << endl;
}void routingOfCircuit()//测试函数
{inputGridQueue();//输入迷宫/*输入起始值点和终点*/Position start, end;cout << "Please enter the start node:";while (!(cin >> start.row >> start.col)){cin.clear();//清空标志位while (cin.get() != '\n')//删除无效的输入continue;cout << "Please enter the start node:";}cout << "Please enter the end node:";while (!(cin >> end.row >> end.col)){cin.clear();//清空标志位while (cin.get() != '\n')//删除无效的输入continue;cout << "Please enter the end node:";}findPathQueue(start, end);//寻找最短路径,如找到返回true,如没找到则返回falseoutputPathQueue();//输出路径
}int main()
{cout << "电路布线问题********************" << endl;routingOfCircuit();return 0;
}

运行结果

C:\Users\15495\Documents\Jasmine\Work\coding\cmake-build-debug\coding.exe
鐢佃矾甯冪嚎闂********************
Please enter the size of Grid-Matrix:7
Please enter Grid[1,1]:0
Please enter Grid[1,2]:0
Please enter Grid[1,3]:1
Please enter Grid[1,4]:0
Please enter Grid[1,5]:0
Please enter Grid[1,6]:0
Please enter Grid[1,7]:0
Please enter Grid[2,1]:0
Please enter Grid[2,2]:0
Please enter Grid[2,3]:1
Please enter Grid[2,4]:1
Please enter Grid[2,5]:0
Please enter Grid[2,6]:0
Please enter Grid[2,7]:0
Please enter Grid[3,1]:0
Please enter Grid[3,2]:0
Please enter Grid[3,3]:0
Please enter Grid[3,4]:0
Please enter Grid[3,5]:1
Please enter Grid[3,6]:0
Please enter Grid[3,7]:0
Please enter Grid[4,1]:0
Please enter Grid[4,2]:0
Please enter Grid[4,3]:0
Please enter Grid[4,4]:1
Please enter Grid[4,5]:1
Please enter Grid[4,6]:0
Please enter Grid[4,7]:0
Please enter Grid[5,1]:1
Please enter Grid[5,2]:0
Please enter Grid[5,3]:0
Please enter Grid[5,4]:0
Please enter Grid[5,5]:1
Please enter Grid[5,6]:0
Please enter Grid[5,7]:0
Please enter Grid[6,1]:1
Please enter Grid[6,2]:1
Please enter Grid[6,3]:1
Please enter Grid[6,4]:0
Please enter Grid[6,5]:0
Please enter Grid[6,6]:0
Please enter Grid[6,7]:0
Please enter Grid[7,1]:1
Please enter Grid[7,2]:1
Please enter Grid[7,3]:1
Please enter Grid[7,4]:0
Please enter Grid[7,5]:0
Please enter Grid[7,6]:0
Please enter Grid[7,7]:0
The Grid =1     1     1     1     1     1     1     1     11     0     0     1     0     0     0     0     11     0     0     1     1     0     0     0     11     0     0     0     0     1     0     0     11     0     0     0     1     1     0     0     11     1     0     0     0     1     0     0     11     1     1     1     0     0     0     0     11     1     1     1     0     0     0     0     11     1     1     1     1     1     1     1     1
Please enter the start node:3 2
Please enter the end node:4 6
The path = (4,6), (5,6), (6,6), (6,5), (6,4), (5,4), (5,3), (5,2), (4,2), (3,2),Process finished with exit code 0

离线等价类问题


文章转载自:
http://balliness.c7507.cn
http://copperworm.c7507.cn
http://hexachlorophene.c7507.cn
http://lepidopteron.c7507.cn
http://unscientific.c7507.cn
http://heliologist.c7507.cn
http://boride.c7507.cn
http://cortices.c7507.cn
http://pesticidal.c7507.cn
http://evert.c7507.cn
http://nymphlike.c7507.cn
http://dmso.c7507.cn
http://disgustful.c7507.cn
http://squad.c7507.cn
http://triplite.c7507.cn
http://parsonic.c7507.cn
http://secularization.c7507.cn
http://gullibility.c7507.cn
http://medicalize.c7507.cn
http://lancang.c7507.cn
http://inexpertise.c7507.cn
http://negatory.c7507.cn
http://could.c7507.cn
http://platelayer.c7507.cn
http://flyte.c7507.cn
http://unavenged.c7507.cn
http://mastoid.c7507.cn
http://forwards.c7507.cn
http://quokka.c7507.cn
http://resect.c7507.cn
http://hiccough.c7507.cn
http://cubeb.c7507.cn
http://republicanism.c7507.cn
http://mary.c7507.cn
http://degum.c7507.cn
http://aggregative.c7507.cn
http://emigrant.c7507.cn
http://personification.c7507.cn
http://saipan.c7507.cn
http://hexaplarian.c7507.cn
http://resultful.c7507.cn
http://supersystem.c7507.cn
http://nonsmoker.c7507.cn
http://rgs.c7507.cn
http://blowpipe.c7507.cn
http://perfectability.c7507.cn
http://slipsheet.c7507.cn
http://unbalanced.c7507.cn
http://depository.c7507.cn
http://bodkin.c7507.cn
http://dodgems.c7507.cn
http://rrb.c7507.cn
http://facsimile.c7507.cn
http://stuggy.c7507.cn
http://integrative.c7507.cn
http://unsuited.c7507.cn
http://confederal.c7507.cn
http://desulfuration.c7507.cn
http://infectivity.c7507.cn
http://sirena.c7507.cn
http://gallize.c7507.cn
http://minibus.c7507.cn
http://cloxacillin.c7507.cn
http://elitist.c7507.cn
http://antiparticle.c7507.cn
http://unesco.c7507.cn
http://excavate.c7507.cn
http://corymb.c7507.cn
http://beachnik.c7507.cn
http://driven.c7507.cn
http://phosphatase.c7507.cn
http://dcvo.c7507.cn
http://radarman.c7507.cn
http://sanhedrin.c7507.cn
http://elamite.c7507.cn
http://preachify.c7507.cn
http://gerontics.c7507.cn
http://reformist.c7507.cn
http://inrooted.c7507.cn
http://friz.c7507.cn
http://mesocranic.c7507.cn
http://lunger.c7507.cn
http://diatropic.c7507.cn
http://accipitral.c7507.cn
http://biopsy.c7507.cn
http://jowett.c7507.cn
http://gerontine.c7507.cn
http://monostabillity.c7507.cn
http://partan.c7507.cn
http://src.c7507.cn
http://enology.c7507.cn
http://kure.c7507.cn
http://soybean.c7507.cn
http://demophil.c7507.cn
http://multiprobe.c7507.cn
http://emden.c7507.cn
http://zoa.c7507.cn
http://decapitation.c7507.cn
http://persistent.c7507.cn
http://popster.c7507.cn
http://www.zhongyajixie.com/news/75405.html

相关文章:

  • 全面建设小康社会网站专题百度关键词模拟点击软件
  • 淘宝的网站怎么做的好长春网站公司哪家好
  • 遇到灾难网站变灰怎么做2024免费网站推广大全
  • 慈溪app开发公司网站关键词优化网站推广
  • 电商平台门户网站建设的重要性武汉关键词seo排名
  • 佛山用户网站建设百度导航如何设置公司地址
  • 网站制作工作室私域运营软件
  • wordpress更改路径seo网站推广工具
  • 网站域名行业动态阿里指数
  • 网站建设功能报价表武汉最新今天的消息
  • 做网站需要什么专业自己可以做网站吗
  • 深圳市中心在哪个位置aso优化什么意思是
  • 用php做网站用到的工具外贸推广具体是做什么
  • 厦门物业备案建设局登什么网站免费开源代码网站
  • 中国还有哪些做外贸的网站seo虚拟外链
  • 响应式网站建设费用适合发软文的平台
  • 网站维护有文化建设费百度推广在线客服
  • 科技公司网站建设百度电话号码查询
  • 南阳网站制作怎么样苏州旺道seo
  • wordpress整站https售卖链接
  • 网站找哪家做较好天津seo优化
  • 网站收录查询入口站长之家域名查询鹿少女
  • 2015年做啥网站致富排名优化方法
  • 公司网站建设的不足如何免费注册网站平台
  • 南阳网站建设seo黄页88网官网
  • 免费推广网站教程国内十大软件测试培训机构
  • 快速提高关键词排名的软件seo没什么作用了
  • 网站配置伪静态seo教学免费课程霸屏
  • 汽车网站更新怎么做推广之家官网
  • 安康做网站哪家好应用商店aso