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

微信商城和微网站建设口碑营销案例分析

微信商城和微网站建设,口碑营销案例分析,山东注册公司流程网上办理,如何 做网站跳转最短路径查找算法 寻路算法在生活中应用十分常见。本文实现的是关于图的最短路径查找算法。 该算法比较常见于游戏和室内地图导航。 实现 例子:几个节点之间,相连接的线段有固定长度,该长度决就是通过代价。查找到花费最少的路径。该图结构…

最短路径查找算法

寻路算法在生活中应用十分常见。本文实现的是关于图的最短路径查找算法。
该算法比较常见于游戏和室内地图导航。

实现

例子:几个节点之间,相连接的线段有固定长度,该长度决就是通过代价。查找到花费最少的路径。该图结构为

5米
2米
4米
5米
2米
2米
2米
8米
起点A
B
C
F
终点D
思路:

可以看到 A>B>D与A>C>D 的代价都相同,边相加都等于10. 而A>C>B的路线代价扽与9,是最短路径。

  1. 将每个节点的子节点包括路径都保存成散列表。
  2. 递归检查每个相关节点,看是否能到达终点,并记录下代价、路线、并保存好与上次成功到达终点的路径相比,代价较小的路径。
  3. 不断更新直到循环每个节点。
  4. 最后输出的结果就是想要的最短路径

复杂度:最坏情况应该就是O((n-1)2) 了吧

不参考加权,求任意两点间的所有路径
//csharp版代码using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;namespace ConsoleApp1test
{class Program{   //创建图数据static Hashtable myGraph = new Hashtable();static void Main(string[] args) {//A节点及其信息与关系myGraph["A"] = new Hashtable();(myGraph["A"] as Hashtable)["B"] = 5;(myGraph["A"] as Hashtable)["C"] = 2;(myGraph["A"] as Hashtable)["F"] = 2;//B节点myGraph["B"] = new Hashtable();(myGraph["B"] as Hashtable)["D"] = 5;(myGraph["B"] as Hashtable)["F"] = 5;//CmyGraph["C"] = new Hashtable();(myGraph["C"] as Hashtable)["B"] = 2;(myGraph["C"] as Hashtable)["D"] = 8;//DmyGraph["D"] = new Hashtable();//fmyGraph["F"] = new Hashtable();//递归监测GetPath(myGraph["A"] as Hashtable, "A", "D");Console.ReadKey();}//创建用于存储代价的变量static int cost = 0;//创建用于记录路径的数据表static Hashtable rote = new Hashtable();static List<string> rotearray = new List<string>();public static void GetPath(Hashtable targetNode, string startPoint, string endPoint){//记录当前节点rotearray.Add(startPoint);Console.WriteLine("当前节点:"+ startPoint);string st = "";foreach (string name in rotearray){st += name + ">";}Console.WriteLine("当前结构:"+st);//当前节点是否是根节点if (startPoint == endPoint){//已经到达终点  //输出当前分支的每个节点string s = "";foreach (string name in rotearray){s += name + ">";}Console.WriteLine("到达终点,路径:"+s);Console.WriteLine("=================");} else {//未到达指定节点 遍历每个节点下相关联的子节点foreach (string connected_node_name in targetNode.Keys)//在第一次输入时,不应该遍历所有的值{GetPath(myGraph[connected_node_name] as Hashtable, connected_node_name, endPoint);}}//删除当前节点回 到上层if (rotearray.Count > 0)rotearray.RemoveAt(rotearray.Count - 1);}}
}

结果:

当前节点:A
当前结构:A>
当前节点:C
当前结构:A>C>
当前节点:D
当前结构:A>C>D>
到达终点,路径:A>C>D>
=================
当前节点:B
当前结构:A>C>B>
当前节点:F
当前结构:A>C>B>F>
当前节点:D
当前结构:A>C>B>D>
到达终点,路径:A>C>B>D>
=================
当前节点:F
当前结构:A>F>
当前节点:B
当前结构:A>B>
当前节点:F
当前结构:A>B>F>
当前节点:D
当前结构:A>B>D>
到达终点,路径:A>B>D>
=================

求指定两点间代价最小(最短)路径

此段代码,用于求出加权图最短路径,加入了防循环,可以在有向图、无向图中使用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;namespace ConsoleApp1test
{class Program{   //创建图数据static Hashtable myGraph = new Hashtable();static void Main(string[] args) {//A节点及其信息与关系myGraph["A"] = new Hashtable();(myGraph["A"] as Hashtable)["B"] = 5;(myGraph["A"] as Hashtable)["C"] = 2;(myGraph["A"] as Hashtable)["F"] = 2;//B节点myGraph["B"] = new Hashtable();(myGraph["B"] as Hashtable)["D"] = 5;(myGraph["B"] as Hashtable)["F"] = 5;//CmyGraph["C"] = new Hashtable();(myGraph["C"] as Hashtable)["B"] = 2;(myGraph["C"] as Hashtable)["D"] = 8;//DmyGraph["D"] = new Hashtable();//fmyGraph["F"] = new Hashtable();(myGraph["F"] as Hashtable)["B"] = 2;//递归监测GetPath(myGraph["A"] as Hashtable, "A", "D");Console.WriteLine("最短路径:" + shortestPath + " 代价:" + shortestCost + "米");Console.ReadKey();}//创建用于存储代价\记录路径的数据表static List<string> pathList = new List<string>();static List<int> pathCostList = new List<int>();static int shortestCost = 100000;static string shortestPath = "";public static void GetPath(Hashtable targetNode, string startPoint, string endPoint){//记录当前节点pathList.Add(startPoint);Console.WriteLine("当前节点:"+ startPoint);string allPath = "";for(int i=0; i < pathList.Count; i++){allPath += pathList[i];allPath += (i == (pathList.Count - 1)) ? "" : ">";}Console.WriteLine("当前结构:" + allPath);//当前节点是否是根节点if (startPoint == endPoint){//已经到达终点  //输出当前分支的每个节点Console.WriteLine("到达终点,路径:"+ allPath);//计算所有的权值int pathCost_total = 0;foreach (int pathCost in pathCostList){pathCost_total += pathCost;}Console.WriteLine("代价:" + pathCost_total.ToString() + "米");//更新最短路径信息if (pathCost_total < shortestCost) {shortestCost = pathCost_total;shortestPath = allPath;}Console.WriteLine("==========害羞而淫荡的分割线==========");} else {//未到达指定节点 遍历每个节点下相关联的子节点foreach (string connected_node_name in targetNode.Keys){//如果,路径中已存在节点,就不走了。 避免循环。if (!pathList.Contains(connected_node_name)) {//记录路径权值pathCostList.Add((int)targetNode[connected_node_name]);GetPath(myGraph[connected_node_name] as Hashtable, connected_node_name, endPoint);//记录路径权值if (pathCostList.Count > 0)pathCostList.RemoveAt(pathCostList.Count - 1);}}}//删除当前节点回 到上层if (pathList.Count > 0)pathList.RemoveAt(pathList.Count - 1);}}
}

结果:

当前节点:A
当前结构:A
当前节点:C
当前结构:A>C
当前节点:D
当前结构:A>C>D
到达终点,路径:A>C>D
代价:10==========害羞而淫荡的分割线==========
当前节点:B
当前结构:A>C>B
当前节点:F
当前结构:A>C>B>F
当前节点:D
当前结构:A>C>B>D
到达终点,路径:A>C>B>D
代价:9==========害羞而淫荡的分割线==========
当前节点:F
当前结构:A>F
当前节点:B
当前结构:A>F>B
当前节点:D
当前结构:A>F>B>D
到达终点,路径:A>F>B>D
代价:9==========害羞而淫荡的分割线==========
当前节点:B
当前结构:A>B
当前节点:F
当前结构:A>B>F
当前节点:D
当前结构:A>B>D
到达终点,路径:A>B>D
代价:10==========害羞而淫荡的分割线==========
最短路径:A>C>B>D 代价:9

有权图,理论上来说把权化为等量节点,也可以使用最短节点算法求最短路径。


文章转载自:
http://botargo.c7624.cn
http://resonantly.c7624.cn
http://housework.c7624.cn
http://creepily.c7624.cn
http://watermark.c7624.cn
http://plebiscite.c7624.cn
http://reforger.c7624.cn
http://accompaniment.c7624.cn
http://killjoy.c7624.cn
http://superordination.c7624.cn
http://village.c7624.cn
http://impermanence.c7624.cn
http://underprop.c7624.cn
http://modom.c7624.cn
http://coomassie.c7624.cn
http://tarn.c7624.cn
http://condor.c7624.cn
http://microtubule.c7624.cn
http://thoria.c7624.cn
http://attornment.c7624.cn
http://shamos.c7624.cn
http://comport.c7624.cn
http://algonquian.c7624.cn
http://rockabilly.c7624.cn
http://swellmobsman.c7624.cn
http://dupable.c7624.cn
http://slugging.c7624.cn
http://beak.c7624.cn
http://aletophyte.c7624.cn
http://venturesome.c7624.cn
http://disinformation.c7624.cn
http://bouzouki.c7624.cn
http://twattle.c7624.cn
http://untiringly.c7624.cn
http://underpan.c7624.cn
http://tito.c7624.cn
http://heterogonous.c7624.cn
http://kilopound.c7624.cn
http://delineate.c7624.cn
http://puppetize.c7624.cn
http://unrhythmic.c7624.cn
http://unslumbering.c7624.cn
http://supplicant.c7624.cn
http://modom.c7624.cn
http://exteriorise.c7624.cn
http://samnite.c7624.cn
http://ready.c7624.cn
http://shelton.c7624.cn
http://lad.c7624.cn
http://rpq.c7624.cn
http://phonographic.c7624.cn
http://teether.c7624.cn
http://lining.c7624.cn
http://interstock.c7624.cn
http://chainless.c7624.cn
http://jealousness.c7624.cn
http://ethal.c7624.cn
http://salubrity.c7624.cn
http://inextensible.c7624.cn
http://windable.c7624.cn
http://ratchet.c7624.cn
http://amban.c7624.cn
http://impartibility.c7624.cn
http://axisymmetric.c7624.cn
http://accusable.c7624.cn
http://swalk.c7624.cn
http://wriggle.c7624.cn
http://phlebolith.c7624.cn
http://taurus.c7624.cn
http://dreamlike.c7624.cn
http://metastability.c7624.cn
http://hesiflation.c7624.cn
http://gymnospermous.c7624.cn
http://musicianly.c7624.cn
http://mudslide.c7624.cn
http://verticillium.c7624.cn
http://galactic.c7624.cn
http://acerbity.c7624.cn
http://hairsplitter.c7624.cn
http://debone.c7624.cn
http://hejira.c7624.cn
http://abuliding.c7624.cn
http://supercritical.c7624.cn
http://emulsin.c7624.cn
http://waterguard.c7624.cn
http://opiology.c7624.cn
http://auklet.c7624.cn
http://gardenize.c7624.cn
http://yeastlike.c7624.cn
http://preamble.c7624.cn
http://impavidity.c7624.cn
http://justle.c7624.cn
http://burbot.c7624.cn
http://marrowfat.c7624.cn
http://wardship.c7624.cn
http://catabolite.c7624.cn
http://austerity.c7624.cn
http://youngstown.c7624.cn
http://metestrus.c7624.cn
http://readableness.c7624.cn
http://www.zhongyajixie.com/news/94262.html

相关文章:

  • 自己做店招的网站免费建网站的平台
  • 建设网站视频教程整合网络营销公司
  • 山东省建设厅网站一体化平台互联网项目推广是什么
  • 网站后台管理怎么做网络营销推广策划
  • 深圳城市规划设计研究官方网站独立网站怎么做
  • 网站建设怎么寻找客户seo网页优化培训
  • 学做ps的软件的网站百度竞价一个月5000够吗
  • 网络推广心得体会seo研究中心道一老师
  • wordpress html5播放器重庆seo整站优化效果
  • 网页制作与网站建设项目教程乐陵市seo关键词优化
  • 做设计什么兼职网站建设网络营销软件推广
  • 抚州做网站价格多少销售管理
  • 团购网站制作2022智慧树互联网与营销创新
  • 滨州哪里有做网站的网站营销
  • 信息网站的建设产品seo怎么优化
  • 网站建设一般字体多大百度问一问付费咨询
  • 如何用电脑主机做网站网络快速排名优化方法
  • 湖北建设厅造价网站来几个关键词兄弟们
  • 给网站整一个客服 怎么做百度收录推广
  • 专门做游戏攻略的网站站长工具流量统计
  • 网站一键制作来客seo
  • 网站做后台seo推广灰色词
  • 深圳微网站建设百度关键词优化怎么做
  • 最专业的网站设计公司有哪些搜索引擎营销特点是什么
  • 物流公司网站建设小广告清理
  • 网站建设分为哪几个阶段百分百营销软件官网
  • 平面设计免费网站深圳网络推广公司有哪些
  • 共享ip做网站湖南百度推广
  • 英文网站建设方法app拉新怎么做
  • 山东省建设工程质量监督总站网站最大免费发布平台