F - Truck History - poj 1789
有一个汽车公司有很多年的汽车制造历史,所以他们会有很多的车型,现在有一些历史学者来研究他们的历史,发现他们的汽车编号很有意思都是有7个小写字母组成的,而且这些小写字母具有一些特别的意义,比如说一个汽车是有另外一个汽车演变过来的,他们的字母差了有几个不同的,就说明演变多少年(最多也就7年!!),现在就是求这些汽车的总演变史最少有多少时间。
#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的更多相关文章
- (最小生成树)Truck History --POJ -- 1789
链接: http://poj.org/problem?id=1789 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 2213 ...
- Truck History - poj 1789 (Prim 算法)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20884 Accepted: 8075 Description Ad ...
- Truck History POJ - 1789
题目链接:https://vjudge.net/problem/POJ-1789 思路: 题目意思就是说,给定一些长度为7的字符串,可以把字符串抽象为一个点, 每个点之间的距离就是他们本身字符串与其他 ...
- Truck History POJ - 1789 板子题
#include<iostream> #include<cstring> #include<algorithm> #include<stdio.h> u ...
- F - Truck History
F - Truck History #include<cstdio> #include<cstring> #include<iostream> #include&l ...
- poj 1789 prime
链接:Truck History - POJ 1789 - Virtual Judge https://vjudge.net/problem/POJ-1789 题意:先给出一个n,代表接下来字符串的 ...
- poj 1789 Truck History
题目连接 http://poj.org/problem?id=1789 Truck History Description Advanced Cargo Movement, Ltd. uses tru ...
- POJ 1789:Truck History(prim&&最小生成树)
id=1789">Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17610 ...
- POJ 1789 Truck History【最小生成树简单应用】
链接: http://poj.org/problem?id=1789 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
随机推荐
- 【小TIP】记录各种错误【更新中】
最好程序一遍通过,为了提高代码能力,这里将用TIP的形式记录来犯过的错误.不断更新中. *已经转移到闪存.. [150214]WA:检查是否数组开小了. [150212]WA:如果程序中有乘号,需要留 ...
- vim中选择匹配文本删除技巧
试举几例如下: 如何只保留匹配内容行而删除其他行? :v/pattern/d :help :v 如何对每行只保留匹配内容而删除这一行中的其它内容 :%s/^.pattern.$/\1/g 删除包含特定 ...
- poj 1330 LCA (倍增+离线Tarjan)
/* 先来个倍增 */ #include<iostream> #include<cstring> #include<cstdio> #define maxn 100 ...
- 命令行命令mvn
在cmd命令行敲击mvn clean install 默认读取的maven配置文件是D:\software\apache-maven-3.2.1\conf\settings.xml 这个文件里面配置有 ...
- asp.net C# 导出EXCEL数据
if (dt == null) { return ""; } Microsoft.Office.Interop.Excel.Application xlApp = new Micr ...
- 页面添加 mask 遮罩层
var mask = function(){ $('<div>').css({ position: 'fixed', left: 0, top: 0, width: '100%', hei ...
- [转自已]Windos多个文件快速重命名说明+图解
转自己以前的文章,给新博客带点气氛. 1.(复制的)比如在文件夹中包含yin.jpg.ye.jpg.zou.jpg三个文件,你希望将它们命名为"photo+数字"的文件名形式,那么 ...
- 导出页面文档(只在IE8下测试过)
之前说过一篇关于打印的方法,就顺便也看了一下导出,但是该方法需要用户更改浏览器的安全级别设置,因此并不十分推荐,大家如真有需要可以参考一下ZeroClipboard这款插件,我有时间也会去学习一下并贴 ...
- ThinkPHP 使用极光推送给ios推送消息
HTML <div id="wrap"><a href="<{:U('Push/pushData')}>">推送</a ...
- 初学Javascript对象
<script> var p=new Object(); //属性 p.width=; p.height=; p.num=; p.autotime=; //方法 p.autoplay=fu ...