• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            AOJ--The Max Weight--Floyd Folyd算法變形,把求最短路徑的和改為求最大載重量的問題

            The Max Weight
            Time Limit: 1000 ms   Memory Limit: 64 MB
            Total Submission: 36   Accepted: 4
            Description
            There a lot of bridges connect different positions in Venice,but they can't carry too much weigh,so each of them has a limit which can be described as an interger.A man wants to carry some goods from positon 1 to n.Help him find how much can he carry.

            Input
            There are T cases.
            For each case,the number of positions ( 1 < = n < = 100) and number m of bridges are exhibited on the first line.The following m lines contain triples of integers specifying start and end positions of the bridge and the maximum allowed weight, which is positive and not larger than 1000000. There will be at most one bridge between each pair of crossings.

            Output
            The output for every scenario begins with a line containing "Case #i:", where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that the man can transport. Terminate the output for the scenario with a blank line.

            Sampel Input
            1
            3 3
            1 2 3
            1 3 4
            2 3 5 

            Sample Output
            Case #1:[EOL]
            4[EOF]

            題意:
            n個點,有些點間有橋,橋上有最大承重量,問你從1到n可以最大攜帶的物品的重量。
            題解: 
             Folyd算法變形,把求最短路徑的和改為求最大載重量的問題,關鍵是dis[i][j]=dis[i][j]>dis[i][k]+dis[k][j]?dis[i][j]>dis[i][k]+dis[k][j]?:dis[i][j];換成dis[i][j]=max(dis[i][j],min(dis[i][k],dis[k][j]));
             1#include<iostream>
             2#include<cmath>
             3#include<string.h>
             4using namespace std;
             5long long dis[105][105];
             6 
             8void Floyd(int n)
             9{
            10     for(int k=1; k<=n; k++)
            11     for(int i=1; i<=n; i++)
            12     for(int j=1; j<=n; j++)
            13     {
            14       if(i!=k&&j!=k&&dis[i][k]&&dis[k][j])
            15         dis[i][j]=max(dis[i][j],min(dis[i][k],dis[k][j]));
            16     }

            17}

            18
            19int main()
            20{
            21    int t,i,j,m,n;
            22    cin>>t;
            23    for(int k=1; k<=t; k++)
            24    {
            25      cin>>n>>m;
            26      memset(dis,0,sizeof (dis));
            27      i=1;
            28      for(int s,e,w; i<=m; i++)
            29      {
            30        cin>>s>>e>>w;
            31        dis[s][e]=dis[e][s]=w;
            32      }

            33      
            34      Floyd(n);
            35      
            36     cout<<"Case #"<<k<<':'<<endl<<dis[1][n]<<endl<<endl;
            37    }

            38    return 0;
            39}

            posted on 2010-05-29 22:03 田兵 閱讀(1462) 評論(0)  編輯 收藏 引用 所屬分類: 圖論題

            <2010年5月>
            2526272829301
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

            導航

            統計

            常用鏈接

            留言簿(2)

            隨筆分類(65)

            隨筆檔案(65)

            文章檔案(2)

            ACM

            搜索

            積分與排名

            最新隨筆

            最新評論

            閱讀排行榜

            伊人久久精品无码av一区| 久久综合香蕉国产蜜臀AV| 久久99精品免费一区二区| 久久久久久亚洲精品不卡 | 久久久久国色AV免费看图片| 青青青青久久精品国产h久久精品五福影院1421 | 777久久精品一区二区三区无码| 久久成人永久免费播放| 亚洲AV日韩AV天堂久久| 久久亚洲天堂| 一本一道久久精品综合| 久久亚洲精精品中文字幕| 久久综合精品国产一区二区三区 | 94久久国产乱子伦精品免费| 久久久黄色大片| 久久e热在这里只有国产中文精品99 | 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区| 久久国产精品视频| www性久久久com| 久久精品蜜芽亚洲国产AV| 精品国产青草久久久久福利| 亚洲成av人片不卡无码久久| 51久久夜色精品国产| 亚洲成人精品久久| 精品一区二区久久久久久久网站| 伊人久久大香线蕉亚洲| 777午夜精品久久av蜜臀| 久久笫一福利免费导航| 久久国产AVJUST麻豆| 欧美大战日韩91综合一区婷婷久久青草| 久久国产乱子伦精品免费强| 97久久天天综合色天天综合色hd | 久久精品免费网站网| 久久精品三级视频| 亚洲?V乱码久久精品蜜桃 | 久久精品无码专区免费 | 久久国产综合精品五月天| 久久青草国产手机看片福利盒子| 国产综合久久久久| 婷婷久久综合九色综合98| 久久99亚洲综合精品首页|