• <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>
            隨筆 - 19, 文章 - 0, 評論 - 2, 引用 - 0
            數(shù)據(jù)加載中……

            hdu1102_Constructing Roads

                    雖然這一題已經(jīng)寫過了,但是我覺得這里有問題。因為題目中有這樣的一句話:
                    We say two village A and B are connected, if and only if there is a road between A and B, or there exists a village C such that there is a road between A and C, and C and B are connected.
                    這樣一來,如果是A-B-C-D,我們能說A和D是相通的嗎?我覺得不能,但是參考別人的代碼時,他們都沒有考慮這一中情況,我也寫了一個沒有考慮的。竟然過了!不知道為什么。我主要是在練習算法,難道是我理解錯了?

            #include <stdio.h>
            #define DEBUG 1
            const int Max = 0x7fffffff ;
            const int N = 111 ;
            int n, dis[N], used[N], closest[N], map[N][N] ;

            int Prim( )
            {
                
            int i, j, index, min, len ;
                
            for( i=1; i<=n; ++i ){
                    used[i] 
            = 0 ;
                    dis[i] 
            = map[1][i] ;
                }

                used[
            1= 1 ;
                len 
            = 0 ;
                
            for( i=1; i<n; ++i ){
                    min 
            = Max ;
                    
            for( j=1; j<=n; ++j ){
                        
            if!used[j] && min>dis[j] ){
                            index 
            = j ;
                            min 
            = dis[j] ;
                        }

                    }

                    used[index] 
            = 1 ;
                    len 
            += dis[index] ;
                    
            for( j=1; j<=n; ++j ){
                        
            if!used[j] && dis[j]>map[j][index] )
                            dis[j] 
            = map[j][index] ;
                    }

                }

                
            return len ;
            }

            int main()
            {
                
            #if DEBUG
                 freopen(
            "C:\\Documents and Settings\\Administrator\\桌面\\in.txt","r",stdin);
                 freopen(
            "C:\\Documents and Settings\\Administrator\\桌面\\out.txt","w",stdout);
                 
            #endif
                 
                
            int i, j, x, y, comp ;
                
            while( EOF != scanf("%d"&n ) && n ){
                    
            for( i=1; i<=n; ++i ){
                        
            for( j=1; j<=n; ++j ){
                            scanf(
            "%d"&map[i][j] ) ;
                            map[j][i] 
            = map[i][j] ;
                        }

                    }

                    scanf(
            "%d"&comp ) ;
                    
            for( i=1; i<=comp; ++i ){
                        scanf(
            "%d%d"&x, &y ) ;
                        map[x][y] 
            = map[y][x] = 0 ;
                    }

                    printf(
            "%d\n", Prim( ) ) ;
                }
                                
                
            return 0 ;
            }

            posted on 2009-05-05 15:26 祝你好運! 閱讀(288) 評論(1)  編輯 收藏 引用

            評論

            # re: hdu1102_Constructing Roads[未登錄]  回復  更多評論   

            無語了,也沒說幾組數(shù)據(jù)啊。。。。。。。。。。。。
            2009-05-07 20:24 | 小白
            女同久久| 狠狠色丁香婷综合久久| 99久久99久久精品国产片果冻 | 久久久久香蕉视频| 久久这里只精品99re66| 久久99热只有频精品8| 午夜视频久久久久一区| 国内精品久久久久影院日本 | 亚洲狠狠综合久久| 中文字幕无码久久精品青草| 国产精品视频久久| 久久久久av无码免费网| 99久久国产综合精品网成人影院| 精品多毛少妇人妻AV免费久久| 欧美久久综合性欧美| 久久香蕉超碰97国产精品| 欧美一级久久久久久久大片| 中文字幕成人精品久久不卡| 久久婷婷五月综合国产尤物app| 亚洲国产精品综合久久一线| 99久久久久| 色综合久久中文综合网| 欧美亚洲色综久久精品国产| 超级97碰碰碰碰久久久久最新| www亚洲欲色成人久久精品| 久久国产精品成人片免费| 99精品国产综合久久久久五月天 | 99久久精品国产一区二区| 久久免费视频一区| 久久久久综合中文字幕| segui久久国产精品| 91超碰碰碰碰久久久久久综合| 久久精品人人做人人爽电影蜜月| 久久婷婷国产剧情内射白浆| 精品久久久久久无码不卡| 久久亚洲天堂| 伊人色综合久久天天人守人婷| 中文字幕久久精品| 久久丫忘忧草产品| 亚洲日韩中文无码久久| 久久久久亚洲av无码专区喷水 |