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

            poj1258

             Agri-Net

            Time Limit: 1000MS Memory Limit: 10000K
            Total Submissions: 25093 Accepted: 9868
            Description
            Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course.
            Farmer John ordered a high speed connection for his farm and is going to share his connectivity with the other farmers. To minimize cost, he wants to lay the minimum amount of optical fiber to connect his farm to all the other farms.
            Given a list of how much fiber it takes to connect each pair of farms, you must find the minimum amount of fiber needed to connect them all together. Each farm must connect to some other farm such that a packet can flow from any one farm to any other farm.
            The distance between any two farms will not exceed 100,000.

            Input

            The input includes several cases. For each case, the first line contains the number of farms, N (3 <= N <= 100). The following lines contain the N x N conectivity matrix, where each element shows the distance from on farm to another. Logically, they are N lines of N space-separated integers. Physically, they are limited in length to 80 characters, so some lines continue onto others. Of course, the diagonal will be 0, since the distance from farm i to itself is not interesting for this problem.

            Output

            For each case, output a single integer length that is the sum of the minimum length of fiber required to connect the entire set of farms.

            Sample Input

            4
            0 4 9 21
            4 0 8 17
            9 8 0 16
            21 17 16 0
            

            Sample Output

            28

            很顯然求這個圖的最小生成樹

            然后我就打算寫prim了,寫完了之后覺得沒錯了,但是交了好幾遍都wa了,

            真心不知道錯誤在哪里,然后去看discuss,才注意到這句話

            Physically, they are limited in length to 80 characters, so some lines continue onto others.

            當(dāng)時(shí)看題時(shí)候沒看明白,看別人說的,沒行還有多余的數(shù)據(jù)


            我就惡心了,我以前寫pascal還有readln可用,現(xiàn)在C語言有不是很熟,用什么代替呢,想了半天沒想出來

            還有人說數(shù)據(jù)范圍不止這些,不過后來驗(yàn)證后,數(shù)據(jù)范圍就是100

            我就去找題解了

            好多題解我發(fā)現(xiàn)都沒注意這一點(diǎn),然后我就納悶了,有看discuss,又有人說,不用注意這句話,我就納悶了,我找了個題解交了之后居然過了

            我就在想,是不是我的prim出錯了呢

            結(jié)果一不小心瞥見,ans居然和vis一塊定義的,定義成short了,

            呃……直接無語了

            #include<stdio.h>
            #include
            <string.h>
            #include
            <math.h>
            #define MAX 505
            int map[MAX][MAX],cost[MAX];
            short vis[MAX];
            int ans;
            int n;
            void prim()
            {
                
            int i,j,mini,min;
                memset(vis,
            0,sizeof(vis));
                vis[
            1]=1;
                ans
            =0;
                
            for (i=1; i<=n; i++)
                    cost[i]
            =0x7fffffff;
                
            for (i=2; i<=n; i++)
                        cost[i]
            =map[1][i];
                
            for (i=1; i<=n-1; i++)
                
            {
                    min
            =0x7fffffff;
                    
            for (j=1; j<=n; j++)
                        
            if ((vis[j]==0)&&(cost[j]<min))
                        
            {
                            min
            =cost[j];
                            mini
            =j;
                        }

                    vis[mini]
            =1;
                    ans
            =ans+min;
                    
            for (j=1; j<=n ; j++ )
                        
            if ((vis[j]==0)&&(map[mini][j]>0)&&(map[mini][j]<cost[j]))
                            cost[j]
            =map[mini][j];
                }

            }

            void init()
            {
                
            int i,j;
                memset(map,
            0,sizeof(map));
                
            for (i=1; i<=n ; i++ )
                
            {
                    
            for (j=1; j<=n ; j++ )
                    
            {
                        scanf(
            "%d",&map[i][j]);
                    }

                }

            }

            int main()
            {
                ;
                
            while (scanf("%d",&n)!=EOF)
                
            {
                    init();
                    prim();
                    printf(
            "%d\n",ans);
                }

                
            return 0;
            }


             

            posted on 2012-02-14 12:57 jh818012 閱讀(202) 評論(0)  編輯 收藏 引用

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因?yàn)?3 的 二進(jìn)制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內(nèi)容較長,點(diǎn)擊標(biāo)題查看
            • --王私江
            爱做久久久久久| 久久国产福利免费| 国产精品无码久久综合 | 性高朝久久久久久久久久| 久久夜色精品国产噜噜亚洲a| 国产精品久久久香蕉| 久久久久99精品成人片直播| 国産精品久久久久久久| 精品综合久久久久久98| 国产精品VIDEOSSEX久久发布| 久久人搡人人玩人妻精品首页| 亚洲AV日韩精品久久久久| 曰曰摸天天摸人人看久久久| 一本久久a久久精品亚洲| 国产成人无码精品久久久久免费 | 久久99精品久久久久久9蜜桃| 伊人久久大香线蕉无码麻豆| 成人国内精品久久久久一区| 久久久久久午夜精品| 狠狠人妻久久久久久综合蜜桃| 久久久久久久97| 国产99久久久国产精品小说| 久久精品国产欧美日韩| 国产精品熟女福利久久AV| 久久婷婷五月综合色奶水99啪| 18禁黄久久久AAA片| 午夜视频久久久久一区| 香蕉99久久国产综合精品宅男自 | 精品久久久久久久久久中文字幕 | 国产午夜电影久久| 99久久精品国产综合一区| 国产精品一久久香蕉国产线看观看| 久久久久亚洲AV无码专区首JN | 国产福利电影一区二区三区,免费久久久久久久精 | 亚洲精品乱码久久久久久按摩| 久久久免费观成人影院| 91久久精品国产免费直播| 久久国产精品无码HDAV | 久久播电影网| 香蕉久久影院| 伊人久久大香线蕉av不卡|