• <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>
            #include <iostream>
            #include 
            <vector>
            #include 
            <algorithm>

            using namespace std;

            struct Edge
            {
                
            int row;
                
            int column;
                
            int value;

                Edge()
                
            {}

                Edge( 
            int a, int b, int c )
                    :row(a),column(b),value(c)
                
            {}
            }
            ;

            bool operator<( Edge const& Itema, Edge const& Itemb )
            {
                
            return Itema.value> Itemb.value;
            }


            vector
            <Edge> graph;
            int          visite[2001];
            char         ch[2001][8];

            int find( int x )
            {
                
            if ( x!= visite[x] )
                    
            return find( visite[x] );

                
            return x;
            }


            int distance( char str1[8], char str2[8] )
            {
                
            int num= 0;

                
            for ( int i= 0; i< 8++i )
                    
            if ( str1[i]!= str2[i] )
                        num
            ++;

                
            return num;
            }


            int main()
            {
                
            int n;

                
            while ( scanf("%d",&n), n )
                
            {
                    
            for ( int i= 0; i< n; ++i )
                        scanf(
            "%s",ch[i] );

                    graph.reserve ( n
            + 1 );

                    
            for ( int i= 0; i< n; ++i )
                    
            {
                        
            for ( int j= 0; j< i; ++j )
                            graph.push_back (  Edge( j,i,distance( ch[i], ch[j] ) ) );
                
                        visite[i]
            = i;
                    }


                    make_heap( graph.begin (), graph.end () );
                    
            int sum= 0;
                    
            int num= 1;

                    
            while ( num< n )
                    
            {
                        
            int u,v;
                        
            if ( (u= find(graph[0].column))!= (v= find(graph[0].row ) ) )
                        
            {
                            sum
            += graph[0].value;
                            visite[v]
            = u;
                            num
            ++;
                        }


                        pop_heap( graph.begin (), graph.end () );
                        graph.pop_back ();
                    }


                    printf( 
            "The highest possible quality is 1/%d.\n", sum );

                    graph.clear ();
                }


                
            return 0;
            }
            posted on 2008-11-06 12:00 Darren 閱讀(234) 評論(3)  編輯 收藏 引用

            評論:
            # re: Pku 1789 Truck History 2008-11-06 12:42 | infinity
            這題好像就是一個最小生成樹吧!  回復  更多評論
              
            # re: Pku 1789 Truck History 2008-11-06 13:02 | Darren
            @infinity
            這是最小生成樹, 我用的是kruskal算法  回復  更多評論
              
            # re: Pku 1789 Truck History 2008-11-06 14:03 | ******
            我的做法:
            串兩兩比較,匹配他們,統計不同的字符數,然后就產生了一張抽象的權值圖
            然后prim  回復  更多評論
              
            国内高清久久久久久| 99久久99久久| 久久久精品久久久久影院| 久久只有这里有精品4| 欧美大香线蕉线伊人久久| 久久免费美女视频| 性做久久久久久久久久久| 久久久久亚洲精品日久生情| 国产成人无码久久久精品一| 老司机午夜网站国内精品久久久久久久久| 日韩人妻无码一区二区三区久久99| 九九精品99久久久香蕉| 99久久www免费人成精品| 国内精品伊人久久久影院| 91精品国产乱码久久久久久| 中文精品99久久国产 | 亚洲日韩欧美一区久久久久我| 人妻精品久久久久中文字幕一冢本| 国产精品gz久久久| 久久香蕉超碰97国产精品| 久久男人AV资源网站| 久久综合丁香激情久久| 久久综合狠狠综合久久综合88| 久久精品无码免费不卡| 青青草原1769久久免费播放 | 久久精品欧美日韩精品| 久久久国产99久久国产一| 久久国产乱子伦精品免费午夜| 久久精品麻豆日日躁夜夜躁| 久久精品国产清自在天天线| 久久人人爽人爽人人爽av| 99久久精品免费看国产| 久久国产高清字幕中文| 久久人人妻人人爽人人爽| 久久精品国产男包| 久久亚洲日韩看片无码| 久久精品中文无码资源站| 婷婷久久综合九色综合绿巨人| 久久精品亚洲精品国产欧美| 国产激情久久久久影院小草| 久久精品国产91久久麻豆自制|