Truck History
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 21518   Accepted: 8367

Description

Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other for furniture, or for bricks. The company has its own code describing each type of a truck. The code is simply a string of exactly seven lowercase letters (each letter on each position has a very special meaning but that is unimportant for this task). At the beginning of company's history, just a single truck type was used but later other types were derived from it, then from the new types another types were derived, and so on.

Today, ACM is rich enough to pay historians to study its history. One thing historians tried to find out is so called derivation plan -- i.e. how the truck types were derived. They defined the distance of truck types as the number of positions with different letters in truck type codes. They also assumed that each truck type was derived from exactly one other truck type (except for the first truck type which was not derived from any other type). The quality of a derivation plan was then defined as 
1/Σ(to,td)d(to,td)
where the sum goes over all pairs of types in the derivation plan such that to is the original type and td the type derived from it and d(to,td) is the distance of the types. 
Since historians failed, you are to write a program to help them. Given the codes of truck types, your program should find the highest possible quality of a derivation plan. 

Input

The input consists of several test cases. Each test case begins with a line containing the number of truck types, N, 2 <= N <= 2 000. Each of the following N lines of input contains one truck type code (a string of seven lowercase letters). You may assume that the codes uniquely describe the trucks, i.e., no two of these N lines are the same. The input is terminated with zero at the place of number of truck types.

Output

For each test case, your program should output the text "The highest possible quality is 1/Q.", where 1/Q is the quality of the best derivation plan.

Sample Input

4
aaaaaaa
baaaaaa
abaaaaa
aabaaaa
0

Sample Output

The highest possible quality is 1/3.

我也是挺纳闷 为什么我把 建图和prime算法过程 写作子函数放在main函数外边怎么就不能调用呢?
题意:给出卡车的编号,编号是一个长度为7的字符串,一个编号由另一个编号衍生出来,而衍生出来所需要的代价就是两个编号之间不同字符的个数
(相当于两个顶点相连后的权值),现在求给出的这组字符串所需要的最小代价
#include<stdio.h>
#include<string.h>
#define MAX 2010
#define INF 0x3ffffff
int map[MAX][MAX];
char s[MAX][11];
int low[MAX],vis[MAX];
int t;
int fun(int i,int j)
{
int ans=0;
for(int k=0;k<7;k++)
{
if(s[i][k]!=s[j][k])
ans++;
}
return ans;
}
void init()
{
int i,j;
for(i=0;i<t;i++)
{
for(j=0;j<t;j++)
{
if(i==j)
map[i][j]=0;
else
map[i][j]=INF;
}
}
}
int main()
{
int t;
int i,j;
while(scanf("%d",&t),t)
{
init();
for(i=0;i<t;i++)
scanf("%s",s[i]);
for(i=0;i<t-1;i++)
{
for(j=i+1;j<t;j++)
{
map[i][j]=map[j][i]=fun(i,j);
}
}
int next,min,mindis=0;
memset(vis,0,sizeof(vis));
for(i=0;i<t;i++)
low[i]=map[0][i];
vis[0]=1;
for(i=0;i<t-1;i++)
{
min=INF;
for(j=0;j<t;j++)
{
if(!vis[j]&&min>low[j])
{
min=low[j];
next=j;
}
}
mindis+=min;
vis[next]=1;
for(j=0;j<t;j++)
{
if(!vis[j]&&low[j]>map[next][j])
low[j]=map[next][j];
}
}
printf("The highest possible quality is 1/%d.\n",mindis);
}
return 0;
}

  

poj 1789 Truck History【最小生成树prime】的更多相关文章

  1. poj 1789 Truck History 最小生成树

    点击打开链接 Truck History Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15235   Accepted:  ...

  2. poj 1789 Truck History 最小生成树 prim 难度:0

    Truck History Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19122   Accepted: 7366 De ...

  3. POJ 1789 -- Truck History(Prim)

     POJ 1789 -- Truck History Prim求分母的最小.即求最小生成树 #include<iostream> #include<cstring> #incl ...

  4. Kuskal/Prim POJ 1789 Truck History

    题目传送门 题意:给出n个长度为7的字符串,一个字符串到另一个的距离为不同的字符数,问所有连通的最小代价是多少 分析:Kuskal/Prim: 先用并查集做,简单好写,然而效率并不高,稠密图应该用Pr ...

  5. poj 1789 Truck History

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

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

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

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

    Truck History 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/E Description Advanced Carg ...

  8. POJ 1789 Truck History (Kruskal)

    题目链接:POJ 1789 Description Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks ...

  9. POJ 1789 Truck History (Kruskal 最小生成树)

    题目链接:http://poj.org/problem?id=1789 Advanced Cargo Movement, Ltd. uses trucks of different types. So ...

随机推荐

  1. ios专题 - OCUnit

    OCUnit是集成在Xcode开发环境的单元测试框架:OCUnit运行必须包含SenTestingKit.framework这个库: 针对需要测试的类,每个类写出自己的TestCase,独立组织一个文 ...

  2. [Lua]表驱动索引编程,form.lua

    form.interface local form = {_tag = 'form'} function form.build(tag, super) --[[ -- form to produce ...

  3. clipboard让复制的文本换行

    https://clipboardjs.com/dist/clipboard.min.js 用clipboard实现复制时, 想让复制的文本换行, 有两咱方法: 第一种, HTML实现: <!- ...

  4. sharepoint读取站点下列表

    前言 还是自己做着练习,也算对这个代码的一个认识吧.东西没什么. 过程 这是后台的一下代码,其中我会对标注的地方解释一下. 标注1:是获取的列表中的某一个列名,标注2:是这个列表下的数据列的名称,我们 ...

  5. angular 实例笔记之嵌套指令间的传参

    最近在项目中遇到了需要嵌套指令的情况,指令在嵌套后子指令必须获得父指令中的数据来进行判断,但是在写传参的时候遇到了坑,因此记录下来,防止以后遗忘,个人的肤浅理解,欢迎大家留言讨论 首先,关于direc ...

  6. 11-17的学习总结(DOMfirstday)

    HTML: 超文本标记语言,专门定义网页内容的语言 XHTML: 严格的HTML标准 DHTML: 所有实现网页动态效果技术的统称 XML: 可扩展的标记语言,标签都是自定义的 XML语法和HTML语 ...

  7. 用Django搭建个人博客—(3)

    今日主题 定义博客文章和评论的的数据库定义 定义操作这几个Model的后台数据 User表 USER_STATUS = ( ('active', u'激活'), ('suspended', u'禁用' ...

  8. 实用lsof常用命令行

    1, 使用 lsof 命令行列出所有打开的文件 # lsof 这可是一个很长的列表,包括打开的文件和网络 上述屏幕截图中包含很多列,例如 PID.user.FD 和 TYPE 等等. FD - Fil ...

  9. PS证件照换背景

    综述 博主原创内容. 在PS里,对于抠图,比较有技术含量的便是抠头发丝了,下面为大家带来一个比较详细的抠头发丝的教程. 素材准备 在这里我们用这张图片作为抠图素材,下面让我们一步步来演示抠图的过程,并 ...

  10. python相关的工具

    在使用python的时候,发现Adaconda工具包真的很不错,里面集合了很多的工具,并且,自带了很多的python常用模块 另外,PyCharm编辑器也是不错的,界面清晰,可以实现数据的可视化