• <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
            • 評論內容較長,點擊標題查看
            • --王私江
            亚洲精品国产字幕久久不卡| 久久久久久国产精品无码下载 | 欧美一区二区三区久久综| 久久国产色av免费看| 久久久久久精品免费免费自慰| 伊人久久大香线蕉精品不卡 | 久久精品无码一区二区app| 日韩欧美亚洲国产精品字幕久久久| yy6080久久| 精品永久久福利一区二区| 国产午夜福利精品久久| 久久久久久久91精品免费观看| 久久99精品久久久久久久久久 | 亚洲精品美女久久久久99小说 | 久久天天躁狠狠躁夜夜2020老熟妇 | 国产亚洲精品久久久久秋霞| 2021少妇久久久久久久久久| 欧美午夜A∨大片久久| 国产精品久久久久久吹潮| 理论片午午伦夜理片久久| 久久精品无码午夜福利理论片| 久久精品国产精品亚洲人人| 无码伊人66久久大杳蕉网站谷歌 | 欧美丰满熟妇BBB久久久| 狠狠色综合久久久久尤物| 人妻无码αv中文字幕久久 | 久久婷婷五月综合色奶水99啪| 91超碰碰碰碰久久久久久综合| 色综合久久久久无码专区 | 一本色综合网久久| 亚洲午夜精品久久久久久app| 国产成人无码精品久久久久免费 | 亚洲国产精品婷婷久久| 国产婷婷成人久久Av免费高清| 成人午夜精品无码区久久| 久久久久国产精品麻豆AR影院| 青青青青久久精品国产| 国产精品久久久久久久| 久久国产免费观看精品| 大美女久久久久久j久久| 伊人久久精品线影院|