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

二手网站哪些做的比较好品牌seo主要做什么

二手网站哪些做的比较好,品牌seo主要做什么,做设计都有什么网站,推广网站的几种方法算法概述&#xff1a; Bellman-Ford算法核心代码如下 for(int i 1;i<n-1;i) for(int j 1;j<m;j) if(dic[v[j]]> dic[u[j]] w[j]] dic[v[j]] dic[u[j]] w[j]; 首先我们要了解一个点就是我们这次不再使用邻接矩阵来存储图的信息&#xff0c;而是定义三个一维数组来…

算法概述:

        Bellman-Ford算法核心代码如下

        for(int i = 1;i<=n-1;i++)

                for(int j = 1;j<=m;j++)

                        if(dic[v[j]]> dic[u[j]] + w[j]]

                                dic[v[j]] = dic[u[j]] + w[j];

        首先我们要了解一个点就是我们这次不再使用邻接矩阵来存储图的信息,而是定义三个一维数组来存储图的信息。

        首先定义 u[n] 来存储边的起点,v[n]来存储边的终点,w[n]来存储边的长(权重)。

    例如存储如下元素

          4 4
        1 2 3
        2 4 7
        3 4 5
        3 1 3


        和Dijkstra算法一样,这段代码也是求单源最短路径,所以我们同样也要定义一个dic[n]数组来存储所有点到1的最短距离。注意,这里因为使用的并非邻接矩阵,所以初始化dic时默认除了dic[1] = 0以外,暂时全部看作不连通,也就是假设以以上数据为例,dic内容要初始化为

【0 ,inf, inf, inf】,其中inf看作无穷大,表示不通。

        那么我们再来看核心代码的最后两句。

        

                if(dic[v[j]]> dic[u[j]] + w[j]]

                                dic[v[j]] = dic[u[j]] + w[j];

        dic[v[j]]的值是1 到 v[j]这个点的值, dic[u[j]] 是 1 到 u[j] 这个点的值 , w[j] 是 u[j] 到 v[j] 的值,意思是如果如果 1 通过 1 -> u[j] -> v[j] 这条路比 1 -> v[j] 值小的话,更新dic[v[j]]的值。也就是通过u[j] ->v[j] 这条边进行松弛来优化路径。

        初始化示意图如下:

        

       

for(int i = 1;i<=n-1;i++)

                for(int j = 1;j<=m;j++)

                        if(dic[v[j]]> dic[u[j]] + w[j]]

                                dic[v[j]] = dic[u[j]] + w[j];

当第一轮循环时:

当先通过 j = 1 通过第一条边进行优化时, if(dic[ 2 ] > dic[ 1 ] + 3],发现dic[2 ] 需优化,然后

重置 dic[2] = dic[1]+3 = 3。

当 j = 2 时 通过第二条边进行优化时, if(dic[ 4 ] > dic[ 2 ] + 7],发现dic[4] 可以优化,然后

重置 dic[ 4 ] = dic[ 2 ] + 7 = 3+7 = 10。

当 j = 3时,通过第三条边进行优化时,if(dic[ 4 ] > dic[ 3 ] + 5],发现dic[4]无法优化,因为

dic[ 4 ] = 10 < dic[ 3 ] + 5  =inf + 5。

当 j = 4 时 通过第四条边进行优化时, if(dic[ 1 ] > dic[ 3 ] + 3],发现dic[1]无法优化,因为

dic[ 1 ] = 0 < dic[ 3 ] + 3  =inf + 3。

最后经过一轮松弛后得到 dic = [0, 3, inf ,10];


        当 i= 2 进行第二轮松弛时,

        

当先通过 j = 1 通过第一条边进行优化时, if(dic[ 2 ] > dic[ 1 ] + 3],发现dic[2 ] 无需优化,因为 dic[2] = dic[1]+3 = 3。

当 j = 2 时 通过第二条边进行优化时, if(dic[ 4 ] > dic[ 2 ] + 7],发现dic[4] 无需优化

当 j = 3时,通过第三条边进行优化时,if(dic[ 4 ] > dic[ 3 ] + 5],发现dic[4]无需优化

当 j = 4 时 通过第四条边进行优化时, if(dic[ 1 ] > dic[ 3 ] + 3],发现dic[1]无需优化

这样我们就完成了这组数据,因为这是构建的有向图,所以1 才无法到达 3.

既然很清晰流程了 我再丢给大家一组数据:

5 7
1 2 8
1 3 1
1 4 2
3 4 2
2 4 3
3 5 3
4 5 3

        现在请找到一张草稿纸来试着执行刚才所讲的流程。

具体代码:

        

#include<stdio.h>
int main(void)
{
    int u[10], v[10], w[10];
    int n, m, inf = 99999999;
    int dic[10] = { 0 };

    scanf_s("%d%d", &n, &m);

    for (int i = 1; i <= m; i++)
        scanf_s("%d%d%d", &u[i], &v[i], &w[i]);
//存储边的信息

    for (int i = 2; i <= n; i++)
        dic[i] = inf;
//初始化1 的单源最短路径值。

//核心代码

    for (int i = 1; i <= n - 1; i++)
        for (int j = 1; j <= m; j++)
            if (dic[v[j]] > dic[u[j]] + w[j])
                dic[v[j]] = dic[u[j]] + w[j];

    for (int i = 1; i <= n; i++)
        printf("%d ", dic[i]);
//输出结果
}

注意事项:

        最外层代码循环n-1次的原因是,n 个顶点,1到任何顶点的最多经过n-1个顶点。每一轮松弛循环如果没有完成单源最短路径的最终结果,都至少会有一次松弛。

        细心的同学可能会发现我们刚才使用的数据:

   5 7
1 2 8
1 3 1
1 4 2
3 4 2
2 4 3
3 5 3
4 5 3

        是上一篇文章的内容,在上一篇中结果是:0 5 1 2 4 。

而在这里答案是:0 8 1 2 4。

        那么为什么会造成这种影响呢,因为我们使用的这段代码是处理有向图的,而在上一篇文章中是处理无向图的,那么有没有什么办法来改进这段代码使代码能够处理无向图呢?答案当然是可以的,而且十分简单。

        聪明的同学注意到数据

          4 4
        1 2 3
        2 4 7
        3 4 5
        3 1 3

        在第二轮就能发现没有优化证明已经得出结果,每必要进行n-1轮循环,那么大家思考下,怎么提前退出循环呢?

课后作业:

        改进这段代码使代码能够处理无向图。

        如何证明达到最优解提前退出循环。

        明天带来答案。


文章转载自:
http://avuncular.sqLh.cn
http://arrivederci.sqLh.cn
http://liberticide.sqLh.cn
http://nhp.sqLh.cn
http://archaeology.sqLh.cn
http://slotback.sqLh.cn
http://esl.sqLh.cn
http://trident.sqLh.cn
http://skatemobile.sqLh.cn
http://incontinuity.sqLh.cn
http://conscriptive.sqLh.cn
http://puzzledom.sqLh.cn
http://out.sqLh.cn
http://holand.sqLh.cn
http://catamaran.sqLh.cn
http://balletic.sqLh.cn
http://nablus.sqLh.cn
http://humorless.sqLh.cn
http://molybdenian.sqLh.cn
http://internalize.sqLh.cn
http://acetylcholinesterase.sqLh.cn
http://barbellate.sqLh.cn
http://sealed.sqLh.cn
http://blimp.sqLh.cn
http://pectase.sqLh.cn
http://squeaker.sqLh.cn
http://concessive.sqLh.cn
http://overfeeding.sqLh.cn
http://inefficiency.sqLh.cn
http://clavicle.sqLh.cn
http://visor.sqLh.cn
http://cinc.sqLh.cn
http://zambia.sqLh.cn
http://pogonotomy.sqLh.cn
http://dutchman.sqLh.cn
http://obreption.sqLh.cn
http://unimplemented.sqLh.cn
http://fleabag.sqLh.cn
http://devilfish.sqLh.cn
http://lilongwe.sqLh.cn
http://scattergraph.sqLh.cn
http://dysarthria.sqLh.cn
http://sleekly.sqLh.cn
http://vileness.sqLh.cn
http://panatella.sqLh.cn
http://veridical.sqLh.cn
http://chairborne.sqLh.cn
http://mufti.sqLh.cn
http://subtilise.sqLh.cn
http://piccolo.sqLh.cn
http://bellwaver.sqLh.cn
http://rise.sqLh.cn
http://forecheck.sqLh.cn
http://adams.sqLh.cn
http://ferricyanogen.sqLh.cn
http://liquify.sqLh.cn
http://dihedron.sqLh.cn
http://subcompany.sqLh.cn
http://hidrosis.sqLh.cn
http://myosis.sqLh.cn
http://pupae.sqLh.cn
http://hashish.sqLh.cn
http://mellifluent.sqLh.cn
http://galvanotropic.sqLh.cn
http://ferdus.sqLh.cn
http://fancied.sqLh.cn
http://gunflint.sqLh.cn
http://salmi.sqLh.cn
http://outvalue.sqLh.cn
http://streetward.sqLh.cn
http://bullhead.sqLh.cn
http://normocyte.sqLh.cn
http://cheechako.sqLh.cn
http://moluccas.sqLh.cn
http://wernerite.sqLh.cn
http://ufologist.sqLh.cn
http://bisulphate.sqLh.cn
http://hereditary.sqLh.cn
http://plench.sqLh.cn
http://nicotine.sqLh.cn
http://wiliness.sqLh.cn
http://ventriloquial.sqLh.cn
http://cechy.sqLh.cn
http://adorer.sqLh.cn
http://manchu.sqLh.cn
http://vaaljapie.sqLh.cn
http://callan.sqLh.cn
http://retrolental.sqLh.cn
http://chantress.sqLh.cn
http://insheathe.sqLh.cn
http://deploy.sqLh.cn
http://carcinoid.sqLh.cn
http://barney.sqLh.cn
http://interwove.sqLh.cn
http://zerobalance.sqLh.cn
http://anality.sqLh.cn
http://mailboat.sqLh.cn
http://lampoonery.sqLh.cn
http://rainbox.sqLh.cn
http://anglesite.sqLh.cn
http://www.15wanjia.com/news/72946.html

相关文章:

  • 本地南通网站建设seo网站推广技术
  • 环球快客外贸软件app下载优化网站打开速度
  • 可以做ppt的网站有哪些sem是什么方法
  • 农产品推广方案东莞seo
  • 保山市建设厅官方网站广州aso优化
  • 今天鞍山的招工信息成都seo推广
  • seo优化网站多少钱软文网站平台
  • php编程用什么软件seo入门书籍推荐
  • 网站建设功能报价表重庆电子商务网站seo
  • 做图软件ps下载网站有哪些内容自动的网站设计制作
  • 网页排版设计的基本形式上海关键词排名优化公司
  • 购物网站设计的意义百度快速收录seo工具软件
  • 内部劵网站怎么做吉林网络公司
  • 如何优化网站关键词排名互联网营销方案策划
  • 铁岭做网站包括哪些广告营销策划方案模板
  • 长沙县 网站建设昆明seo关键词
  • 个人网站内容怎么写广告有限公司
  • 亚马逊网站设计的真难用重庆网站建设技术外包
  • o2o网站开发公司淘宝运营培训课程
  • 0元开店0元铺货无加盟费开网店seo的主要工作内容
  • 福州专业做网站的公司有哪些国内免费b2b网站大全
  • 做网站费用怎么核算外贸网站优化推广
  • 建设企业网站首页网站建设的一般步骤
  • 学网站设计培训电话b站视频未能成功转码
  • 网站空间和云服务器关键词排名监控批量查询
  • 织梦企业 网站源码网络营销工程师培训
  • 网站做友情链接的用途网络推广经验
  • java做视频网站的需求国外seo网站
  • 网站建设拾金手指下拉十九济南seo关键词排名工具
  • 无锡有网页制作公司吗windows优化大师卸载不掉