• <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 田兵 閱讀(1444) 評論(0)  編輯 收藏 引用 所屬分類: 圖論題

            <2010年6月>
            303112345
            6789101112
            13141516171819
            20212223242526
            27282930123
            45678910

            導航

            統計

            常用鏈接

            留言簿(2)

            隨筆分類(65)

            隨筆檔案(65)

            文章檔案(2)

            ACM

            搜索

            積分與排名

            最新隨筆

            最新評論

            閱讀排行榜

            无码乱码观看精品久久| 久久亚洲私人国产精品| 国产精品99久久久久久宅男| 久久亚洲精品无码观看不卡| 一本一本久久A久久综合精品| 国产Av激情久久无码天堂| 麻豆国内精品久久久久久| 一本一本久久a久久综合精品蜜桃| 国产99久久精品一区二区| 香蕉久久影院| 嫩草影院久久99| 亚洲AV无一区二区三区久久| 久久国产成人亚洲精品影院| 人妻无码αv中文字幕久久| 久久无码国产| 久久最新精品国产| 国产亚洲欧美精品久久久| 老男人久久青草av高清| 99久久人妻无码精品系列蜜桃| 久久天天躁狠狠躁夜夜av浪潮| 国产aⅴ激情无码久久| 久久精品国产精品亚洲下载| 99re这里只有精品热久久| 久久久久久久波多野结衣高潮 | 久久婷婷人人澡人人| 久久ww精品w免费人成| 午夜久久久久久禁播电影| 久久91精品国产91| 99久久免费国产精品特黄| 欧美亚洲日本久久精品| 久久久久亚洲AV成人网人人网站 | 一本色道久久综合狠狠躁| 久久精品极品盛宴观看| 久久伊人影视| 亚洲精品无码久久久久AV麻豆| 青青久久精品国产免费看| 久久性精品| 久久人妻AV中文字幕| 无码伊人66久久大杳蕉网站谷歌| 亚洲中文字幕无码一久久区| 日韩乱码人妻无码中文字幕久久|