• <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>

            USACO--AOJ Bessie Come Home --Floyd算法

            Bessie Come Home

            Time Limit:JAVA/Others2000/1000MS  Memory Limit:JAVA/Others131072/65536KB
            Total Submit:6 Accepted:2

            Description

            It's dinner time, and the cows are out in their separate pastures. Farmer John rings the bell so they will start walking to the barn. Your job is to figure out which one cow gets to the barn first (the supplied test data will always have exactly one fastest cow).

            Between milkings, each cow is located in her own pasture, though some pastures have no cows in them. Each pasture is connected by a path to one or more other pastures (potentially including itself). Sometimes, two (potentially self-same) pastures are connected by more than one path. One or more of the pastures has a path to the barn. Thus, all cows have a path to the barn and they always know the shortest path. Of course, cows can go either direction on a path and they all walk at the same speed.

            The pastures are labeled `a'..`z' and `A'..`Y'. One cow is in each pasture labeled with a capital letter. No cow is in a pasture labeled with a lower case letter. The barn's label is `Z'; no cows are in the barn, though.

            Input

            Line 1: Integer P (1 <= P <= 10000) the number of paths that interconnect the pastures (and the barn)
            Line 2..P+1: Space separated, two letters and an integer: the names of the interconnected pastures/barn and the distance between them (1 <= distance <= 1000)

            Output

            A single line containing two items: the capital letter name of the pasture of the cow that arrives first back at the barn, the length of the path followed by that cow.

            Sample Input

            5
            A d 6
            B d 3
            C e 9
            d Z 8
            e Z 3
            

            Sample Output

            B 11
            

             1Floyd 算法:http://icpc.ahu.edu.cn:8080/AOJ/   做的第一個(gè)圖論題
             2圖的最短路徑問題,到‘Z’的最短路徑;
             3Floyd算法大概知道怎么用了 ,好像是動(dòng)態(tài)規(guī)劃實(shí)現(xiàn)的,不知道為什么這樣是對(duì)的
             4O(N^3)求解最短路徑問題,數(shù)據(jù)范圍超過400可能就危險(xiǎn)了
             5#include<iostream>
             6#include<string.h>
             7using namespace std;
             8int dis[53][53];
             9const int INF=10000000;
            10void Floyd(int n)
            11{
            12     for(int k=1; k<=n; k++)
            13     for(int i=1; i<=n; i++)
            14     for(int j=1; j<=n; j++)
            15      if(i!=k&&k!=j&&i!=j&&dis[i][k]+dis[k][j]<dis[i][j])
            16      dis[i][j]=dis[i][k]+dis[k][j];
            17
            18}

            19
            20
            21int main()
            22{
            23    int p,i,j,k,d,n1,n2; 
            24    cin>>p;
            25    memset(dis,0,sizeof (dis));
            26    for(i=1; i<=52; i++)
            27    for(j=1; j<=52; j++)
            28    dis[i][j]=INF;
            29     
            30    for(i=1; i<=p; i++)
            31    {
            32       char v1,v2;
            33       cin>>v1>>v2>>d;      
            34       if(v1==v2)continue;
            35       n1=(v1>='a'?v1-'a'+1:v1-'A'+26+1);
            36       n2=(v2>='a'?v2-'a'+1:v2-'A'+26+1);
            37       if(d<dis[n1][n2])dis[n1][n2]=dis[n2][n1]=d;
            38    }

            39    
            40    Floyd(52);
            41    
            42    int min=INF+100;
            43    char c;
            44    for(i=27; i<=51; i++//大寫字母到Z 
            45    {
            46       if(dis[i][52]<min){min=dis[i][52];c=i; }
            47    }

            48    cout<<char(c-27+'A')<<' '<<min<<endl;
            49    //system("pause");
            50    return 0;
            51}

            52

            posted on 2010-05-23 20:03 田兵 閱讀(1425) 評(píng)論(1)  編輯 收藏 引用 所屬分類: 圖論題

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

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(2)

            隨筆分類(65)

            隨筆檔案(65)

            文章檔案(2)

            ACM

            搜索

            積分與排名

            最新隨筆

            最新評(píng)論

            閱讀排行榜

            欧洲成人午夜精品无码区久久| 97久久综合精品久久久综合| 国产精品久久久亚洲| 伊人久久综合成人网| 狠狠色丁香久久婷婷综合| 亚洲精品无码专区久久同性男 | 精品久久久久国产免费 | 大伊人青草狠狠久久| 久久精品国产亚洲AV高清热| 久久国产精品无码一区二区三区| 久久人人爽人人爽人人片AV不| 久久久久亚洲精品无码蜜桃| 国产综合久久久久久鬼色| 国产一区二区三区久久| 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久精品国产精品亚洲下载| 欧美精品一区二区精品久久| 亚洲国产精品久久66| 久久亚洲国产成人影院网站 | 国产精品伊人久久伊人电影 | 国产成人精品白浆久久69| 久久99精品久久久久子伦| 国产精品99久久精品| 久久伊人精品青青草原高清| 久久精品免费大片国产大片| 久久精品国产免费观看| 精品一区二区久久| 亚洲婷婷国产精品电影人久久| 久久一日本道色综合久久| 99久久国产综合精品成人影院| 久久久久久国产a免费观看黄色大片 | 久久久亚洲欧洲日产国码二区| 免费观看成人久久网免费观看| 色婷婷狠狠久久综合五月| 久久国产精品99国产精| 一个色综合久久| 女人香蕉久久**毛片精品| 久久精品国产亚洲av日韩| 一级做a爰片久久毛片毛片| 久久婷婷国产麻豆91天堂| 国内高清久久久久久|