有一个汽车公司有很多年的汽车制造历史,所以他们会有很多的车型,现在有一些历史学者来研究他们的历史,发现他们的汽车编号很有意思都是有7个小写字母组成的,而且这些小写字母具有一些特别的意义,比如说一个汽车是有另外一个汽车演变过来的,他们的字母差了有几个不同的,就说明演变多少年(最多也就7年!!),现在就是求这些汽车的总演变史最少有多少时间。

分析:考虑到是个完全图,应该使用prim算法,因为prim是按照点来的,不过还是喜欢krusal,试一下看看能不能过。。
***********************************************************************
很遗憾超时了,我再试一下不更新到底会怎么样,不更新到底能过。。不过也用了700多ms
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<queue>
#include<stack>
using namespace std; const int maxn = ; int f[maxn];
char p[maxn][];
struct node
{
    int u, v, len;
    friend bool operator < (node a, node b)
    {
        return a.len > b.len;
    }
}; int Len(char a[], char b[])
{
    int sum = ;
    for(int i=; a[i]; i++)
        if(a[i] != b[i])sum++;     return sum;
}
int Find(int x)
{
    if(f[x] != x)
        f[x] = Find(f[x]);
    return f[x];
}
int main()
{
    int N;     while(scanf("%d", &N) != EOF && N)
    {
        node s;
        priority_queue<node> Q;         for(s.u=; s.u<=N; s.u++)
        {
            f[s.u] = s.u;
            scanf("%s", p[s.u]);
            for(s.v=; s.v<s.u; s.v++)
            {
                s.len = Len(p[s.u], p[s.v]);
                Q.push(s);
            }
        }
        int ans = , t=;//如果已经链接了N-1条边就可以结束了
        while(Q.size() && t < N-)
        {
            s = Q.top();Q.pop();
            int u = Find(s.u), v = Find(s.v);             if(u != v)
            {
                t++;
                f[v] = u;
                ans += s.len;
            }
        }         printf("The highest possible quality is 1/%d.\n", ans);
    }     return ;

}

F - Truck History - poj 1789的更多相关文章

  1. (最小生成树)Truck History --POJ -- 1789

    链接: http://poj.org/problem?id=1789 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2213 ...

  2. Truck History - poj 1789 (Prim 算法)

      Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 20884   Accepted: 8075 Description Ad ...

  3. Truck History POJ - 1789

    题目链接:https://vjudge.net/problem/POJ-1789 思路: 题目意思就是说,给定一些长度为7的字符串,可以把字符串抽象为一个点, 每个点之间的距离就是他们本身字符串与其他 ...

  4. Truck History POJ - 1789 板子题

    #include<iostream> #include<cstring> #include<algorithm> #include<stdio.h> u ...

  5. F - Truck History

    F - Truck History #include<cstdio> #include<cstring> #include<iostream> #include&l ...

  6. poj 1789 prime

    链接:Truck History - POJ 1789 - Virtual Judge  https://vjudge.net/problem/POJ-1789 题意:先给出一个n,代表接下来字符串的 ...

  7. poj 1789 Truck History

    题目连接 http://poj.org/problem?id=1789 Truck History Description Advanced Cargo Movement, Ltd. uses tru ...

  8. POJ 1789:Truck History(prim&amp;&amp;最小生成树)

    id=1789">Truck History Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17610   ...

  9. POJ 1789 Truck History【最小生成树简单应用】

    链接: http://poj.org/problem?id=1789 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

随机推荐

  1. C#学习第四天

    今天主要学习了结构方面的知识,首先是定义,代码: struct<typeName> { <memberDeclarations> } struct route { public ...

  2. 【开源java游戏框架libgdx专题】-04-接口介绍及生命周期

    在核心项目中包含6大与操作系统交互的接口,每个后端都实现了这6大接口. Application:运行应用程序并通知API的客户端应用程序级别的事件,提供日志记录设施和查询方法,例如,内存使用. Fil ...

  3. Excel 2007中的新文件格式

    *.xlsx:基于XML文件格式的Excel 2007工作簿缺省格式 *.xlsm:基于XML且启用宏的Excel 2007工作簿 *.xltx:Excel2007模板格式 *.xltm:Excel ...

  4. JNI type

    ref: JNI type The mapping between the Java type and C type is: Type Signature Java Type Z boolean B ...

  5. tomcat启动项目内存溢出问题

    catalina.bat文件的第二行加下面的即可: 注意最大内存设置,和系统的内存有关系 set JAVA_OPTS=%JAVA_OPTS% -Xms512m -Xmx1024m -XX:PermSi ...

  6. C++ Built-In Array 的语义

    C++ 编译花了大量精力使得class和原始类(primitive types)的用法一致.比如array的应用: A a[100]:// A is class int b[100]: 虽然a是用户定 ...

  7. hdu 1548 A strange lift (bfs)

    A strange lift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  8. 35 Search Insert Position(找到数的位置Medium)

    题目意思:在递增数组中找到目标数的位置,如果目标数不在数组中,返回其应该在的位置. 思路:折半查找,和相邻数比较,注意边界 class Solution { public: int searchIns ...

  9. Ubuntu16.04下编译vim with python support失败的原因

    - youcompleteme原话:On Ubuntu 16.04, Python support was not working due to enabling both Python2 and P ...

  10. spinner 下拉框控件

    spinnerMode=dropdown时,为下拉模式spinnerMode=dialog时,会在界面中间弹出Android:popupBackground=”#f0000000”,可以去除spinn ...