有一个汽车公司有很多年的汽车制造历史,所以他们会有很多的车型,现在有一些历史学者来研究他们的历史,发现他们的汽车编号很有意思都是有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. Strust2 <c:forEach> 循环控制标签

    <c:forEach>为循环控制标签 语法:迭代一集合对象中的所有成员 <c:forEach [var="varName"] items="collec ...

  2. sharesdk 的使用

    社交分享组件有很多 介绍一下sharesdk 的使用 官网:http://sharesdk.cn/ 1.先上效果图 2.主要代码: public class TestShare extends Act ...

  3. HUD 2089 位数dp

    /* 做的不多的位数dp 暴力的话 不知道多少组数据 会T 所以写dp 思路就和数学课本上那种“不超过xxx的x位偶数有几个” 这里可以类似的维护一个前缀和模样的东西(但又不同于前缀和) 状态:f[i ...

  4. MySQL存储过程(一)

    1.1 CREATE  PROCEDURE (创建) CREATE PROCEDURE存储过程名 (参数列表) BEGIN SQL语句代码块 END 注意: 由括号包围的参数列必须总是存在.如果没有参 ...

  5. MD5加密相关

    demo效果

  6. 关于asp.net程序连接不了ORACLE数据库而PL/SQL可以连接的问题

    今天在发布ASP.NET WEB网站时发现程序连接不了数据 报“ORA-12154: TNS: 无法解析指定的连接标识符”的错误,但PL/SQL连接又没有问题.真莫名其秒.在百度找了好多相关的问题.都 ...

  7. Ext4.1 grid 多选(可无checkbox)

    转载 在Ext4.1中的grid默认只能实现单选的. 如果你想要你的grid有多选功能,需要给grid增加selModel 如果你使用了Ext.create('Ext.selection.Checkb ...

  8. [LeetCode OJ] Reorder List—Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…

    For example,Given {1,2,3,4}, reorder it to {1,4,2,3}. /** * Definition for singly-linked list. * str ...

  9. URL编码详解

    escape,encodeURI,encodeURIComponent. 据说还有base64,但会被 = 来补. 待编辑.

  10. svn更新

    下载配置文件 pwd cd /home/www/xxxx/protected/config/ get main.php 上传配置文件 put main.php svn更新 svn co svn://s ...