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

            poj1789

            Truck History

            Time Limit: 2000MS Memory Limit: 65536K
            Total Submissions: 10998 Accepted: 4092

            Description

            Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other for furniture, or for bricks. The company has its own code describing each type of a truck. The code is simply a string of exactly seven lowercase letters (each letter on each position has a very special meaning but that is unimportant for this task). At the beginning of company's history, just a single truck type was used but later other types were derived from it, then from the new types another types were derived, and so on.

            Today, ACM is rich enough to pay historians to study its history. One thing historians tried to find out is so called derivation plan -- i.e. how the truck types were derived. They defined the distance of truck types as the number of positions with different letters in truck type codes. They also assumed that each truck type was derived from exactly one other truck type (except for the first truck type which was not derived from any other type). The quality of a derivation plan was then defined as


            1/Σ(to,td)d(to,td)



            where the sum goes over all pairs of types in the derivation plan such that to is the original type and td the type derived from it and d(to,td) is the distance of the types.
            Since historians failed, you are to write a program to help them. Given the codes of truck types, your program should find the highest possible quality of a derivation plan.

            Input

            The input consists of several test cases. Each test case begins with a line containing the number of truck types, N, 2 <= N <= 2 000. Each of the following N lines of input contains one truck type code (a string of seven lowercase letters). You may assume that the codes uniquely describe the trucks, i.e., no two of these N lines are the same. The input is terminated with zero at the place of number of truck types.

            Output

            For each test case, your program should output the text "The highest possible quality is 1/Q.", where 1/Q is the quality of the best derivation plan.

            Sample Input

            4
            aaaaaaa
            baaaaaa
            abaaaaa
            aabaaaa
            0
            

            Sample Output

            The highest possible quality is 1/3.
             
            1次AC就是爽撒。
            題目中生詞太多了,有點看不懂,不過還好,還是懂了
            就是有n輛車,每輛車都有一個7位的編號,兩個編號之間的d代表這兩個編號之間不同字母的個數。
            一個編號只能由另一個編號“衍生”出來,代價是這兩個編號之間相應的d,
            現在要找出一個“衍生”方案,使得總代價最小,也就是d之和最小。
            怎么做呢
            以任意兩個車的編號作為節點,這條邊的邊權為兩個編號間不同字母的個數,
            這樣圖就建好了,至于用prim還是用kruskal,就無所謂了
            我用的prim,矩陣來存圖,好費空間啊
            這題確實水了,連我都能1A
             1#include<stdio.h>
             2#include<string.h>
             3#include<math.h>
             4#define MAX 2100
             5char s[MAX][7];
             6int map[MAX][MAX];
             7int n,ans,cost[MAX];
             8short vis[MAX];
             9int cmp(char s1[],char s2[])
            10{
            11    int i,tot;
            12    tot=0;
            13    for (i=0; i<=6 ; i++ )
            14        if (s1[i]!=s2[i]) tot++;
            15    return tot;
            16}

            17void init()
            18{
            19    int i,j;
            20    for (i=1; i<=n ; i++ )
            21        scanf("%s",&s[i]);
            22    memset(map,0,sizeof(map));
            23    for (i=1; i<=n-1 ; i++ )
            24        for (j=i+1; j<=n; j++)
            25        {
            26            map[i][j]=cmp(s[i],s[j]);
            27            map[j][i]=map[i][j];
            28        }

            29}

            30void prim()
            31{
            32    int i,j,mini,min;
            33    memset(vis,0,sizeof(vis));
            34    for (i=2; i<=n; i++) cost[i]=map[1][i];
            35    vis[1]=1;
            36    ans=0;
            37    for (i=1; i<=n-1 ; i++ )
            38    {
            39        min=0x7fffffff;
            40        for (j=1; j<=n ; j++ )
            41            if ((!vis[j])&&(cost[j]<min))
            42            {
            43                min=cost[j];
            44                mini=j;
            45            }

            46        ans=ans+min;
            47        vis[mini]=1;
            48        for (j=1; j<=n ; j++ )
            49            if ((!vis[j])&&(map[mini][j]>0)&&(map[mini][j]<cost[j]))
            50                cost[j]=map[mini][j];
            51    }

            52}

            53int main()
            54{
            55    scanf("%d",&n);
            56    while (n!=0)
            57    {
            58        init();
            59        prim();
            60        printf("The highest possible quality is 1/%d.\n",ans);
            61        scanf("%d",&n);
            62    }

            63    return 0;
            64}

            65

            posted on 2012-02-14 19:03 jh818012 閱讀(299) 評論(0)  編輯 收藏 引用

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

            導航

            統計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內容較長,點擊標題查看
            • --王私江
            久久精品国产99国产精品澳门| 亚洲精品tv久久久久久久久| 久久国产精品国产自线拍免费| 无码国内精品久久人妻| 精品免费久久久久久久| 国产精品久久久久…| 开心久久婷婷综合中文字幕| 精品国产99久久久久久麻豆| 久久久久99精品成人片欧美| 久久精品成人国产午夜| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 久久综合狠狠综合久久综合88 | 中文字幕亚洲综合久久| 中文字幕精品久久久久人妻| 久久久精品2019免费观看| 精品久久久久久无码中文野结衣| 精品综合久久久久久97| segui久久国产精品| 久久国产精品无码HDAV| 久久久久久久波多野结衣高潮 | 无码精品久久久久久人妻中字| 色综合久久中文色婷婷| 伊人久久无码中文字幕| 久久久精品波多野结衣| 国产精品久久久久影院色| 一本色道久久99一综合| 伊人久久成人成综合网222| 国产毛片久久久久久国产毛片 | 久久只有这精品99| 久久久这里有精品中文字幕| 久久精品国产一区| 久久久国产精品福利免费 | 一级a性色生活片久久无| 亚洲国产精品久久久久久| 久久不射电影网| 99热成人精品免费久久| 久久精品九九亚洲精品天堂| 久久99免费视频| 伊人久久综合热线大杳蕉下载| 久久这里只精品国产99热| 欧美精品一区二区精品久久|