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 ...
随机推荐
- oracle的sql优化
http://www.cnblogs.com/rootq/archive/2008/11/17/1334727.html
- 转:SVN使用教程总结
转自:http://www.cnblogs.com/tugenhua0707/p/3969558.html SVN简介: 为什么要使用SVN? 程序员在编写程序的过程中,每个程序员都会生成很多不同的版 ...
- ThinkPHP学习 volist标签高级应用之多重嵌套循环、隔行变色(转)
Action代码: public function index(){ $prod = I("get.prod_en"); $id = I("get.id", 0 ...
- PHP 网页爬虫
只能爬一个页面 <?php function get_urls($url){ $url_array=array(); $the_first_content=file_get_contents($ ...
- ASP.NET 5服务
ASP.NET5已经把web服务从应用程序当中解耦出来了,它支持IIS和IIS Express, 用Kestrel和WebListener自宿主,另外,开发都或者第三方软件提供商都可以自定义开发ASP ...
- div 显示滚动条
overflow-x:auto 显示横向滚动条 overflow-y:hidden 隐藏纵向滚动条 引用此class,只显示横向的滚动条 .max{ margin:auto; overflow- ...
- UILabel,UITextField,UIButton三大基础控件总结
(一)UILabel空件 属性: 1.背景颜色 label.backgroundColor = [UIColor ***]; 2. 显示文字: label.text = @"******&q ...
- Char Varchar Nvarchar区别
char和varchar是一样的字符型,不同在于,varchar比char更灵活,精确,且不占内存空间,当你取同样的字符时,char会在该字符后面加上空格,而varchar则只取得这个字符,比如有字段 ...
- Starting and Stopping Oracle Fusion Middleware
指定用户名密码启动管理服务器 You can start and stop Oracle WebLogic Server Administration Servers using the WLST c ...
- DontDestroyOnLoad
本文由博主(YinaPan)原创,转载请注明出处:http://www.cnblogs.com/YinaPan/p/Unity_DontDestroyOnLoad.html public stati ...