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 ...
随机推荐
- 循序渐近学docker---笔记
1.安装docker 环境:ubuntu 16.04 sudo apt-get install docker.io root@ld-Lenovo-G470:~# docker -vDocker ver ...
- XML 序列化与PULL解析
简介 Pull解析XML XmlPullParser解析器的运行方式与SAX解析器相似.它提供了类似的事件(开始元素和结束元素),但需要使用parser.next()方法来提取它们.事件将作为数值代码 ...
- Tips--怎么使用谷歌搜索
修改hosts即可: hosts在哪? windows下:C:\Windows\System32\drivers\etc 管理员身份打开,并将下载好的hosts文件内容,添加到原有的hosts文件末尾 ...
- Content-Disposition的使用和注意事项
转载:http://www.cnblogs.com/jzaileen/articles/1281025.html 最近不少Web技术圈内的朋友在讨论协议方面的事情,有的说web开发者应该熟悉web相关 ...
- 探究Activity的各回调方法
刚毕业那会儿,一心想朝着java web的方向进军,却岂料实习的时候阴差阳错地踏入了Android的大门,自此人生跌宕起伏.坎坎坷坷,在一家外企参与了几个需要越过GFW才能使用的有关于体育赛事的项目, ...
- oracle系统包——dbms job用法(oracle定时任务)
用于安排和管理作业队列,通过使用作业,可以使ORACLE数据库定期执行特定的任务. 一.dbms_job涉及到的知识点1.创建job:variable jobno number;dbms_job.su ...
- hibernate_validator_05
校验约束 一,认识Validator---Validation中最主要的接口 1.怎么获取一个Validator--Validation.buildDefaultValidatorFactory() ...
- 纯js制作遮罩层对话框 -- g皓皓
//本文支持js在线工具测试.转载请注明出处. <htmlxmlns="http://www.w3.org/1999/xhtml"> <head> < ...
- JQUERY1.9学习笔记 之内容过滤器(一) 包含选择器
描述:选择包含指定文本的所有元素.jQuery( ":contains(text)" ) text:一串大小写敏感的文本. 例:找出所有包含"john"的div ...
- Linux命令——创建删除文件
创建文件夹 mkdir filename 进入目录文件 cd filename 返回上一级目录 cd ..返回多级目录 cd ../../.. (../表示一级) 创建文件 touch filen ...