• <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, 評(píng)論 - 2, 引用 - 0
            數(shù)據(jù)加載中……

            hdu1548 A strange lift

                     又是一道典型的最短路徑的題目,當(dāng)然也可以用搜索,我現(xiàn)在在學(xué)習(xí)最短路徑,所以就用Dijsktra來(lái)做的,一開(kāi)始時(shí)WA了好幾次,是因?yàn)檫@一題是應(yīng)該抽象出來(lái)一個(gè)有向圖,而我卻是用了無(wú)向圖,所以一直WA。最后改了一下,然后就過(guò)了。

            #include <stdio.h>
            #define DEBUG 1
            const int N=300 ;
            const int Max = 10000000 ;
            int n, map[N][N], used[N], dis[N] ;

            void Dijkstra( int a, int b )
            {
                
            int i, j, index, min ;
                
            for( i=1; i<=n; ++i ){
                    dis[i] 
            = map[a][i] ;
                    used[i] 
            = 0 ;
                }

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

                    }

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

                }

                
            if( dis[b] == Max ){
                    
            //printf("%d\n", dis[b] ) ;
                    printf("-1\n") ;
                }
                   
                
            else
                    printf(
            "%d\n", dis[b] ) ;
            }


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

                    scanf(
            "%d%d"&a, &b ) ;
                    
            for( i=1; i<=n; ++i ){
                        scanf(
            "%d"&temp ) ;
                        
            if( i - temp > 0 )
                            map[i][i
            -temp] = 1 ;
                        
            if( i + temp <= n )
                             map[i][i
            +temp] = 1 ;
                    }

                    Dijkstra( a, b ) ;
                }
                     
                
            return 0 ;
            }

            posted on 2009-05-03 21:16 祝你好運(yùn)! 閱讀(371) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            狠狠人妻久久久久久综合蜜桃| 国产毛片久久久久久国产毛片| 久久久受www免费人成| 99国产欧美精品久久久蜜芽| 国产精品久久久久久久app | 欧美亚洲另类久久综合婷婷| 久久免费高清视频| 97久久香蕉国产线看观看| 色综合久久久久综合体桃花网| 久久久无码精品亚洲日韩蜜臀浪潮 | 久久99热这里只有精品国产| 久久精品国产免费| 久久电影网2021| 久久综合久久久| 伊人色综合久久天天| 99久久国产免费福利| 精品熟女少妇aⅴ免费久久| segui久久国产精品| 精品久久久久国产免费 | 热RE99久久精品国产66热| 日韩精品无码久久一区二区三| 久久99精品久久久久久齐齐 | 麻豆精品久久久久久久99蜜桃 | 国产V综合V亚洲欧美久久| 99国产欧美久久久精品蜜芽 | 模特私拍国产精品久久| 久久精品国产久精国产一老狼| 欧洲人妻丰满av无码久久不卡| 久久国产精品无码HDAV| 麻豆精品久久久一区二区| 久久精品亚洲男人的天堂| 思思久久精品在热线热| 精品蜜臀久久久久99网站| 国产综合成人久久大片91| 伊人久久无码精品中文字幕| 狠狠色丁香婷婷久久综合| 伊色综合久久之综合久久| 久久久久青草线蕉综合超碰| 成人久久久观看免费毛片| 久久艹国产| 久久水蜜桃亚洲av无码精品麻豆 |