题意  有n辆卡车  每辆卡车用7个字符表示  输入n  再输入n行字符  第i行与第j行的两个字符串有多少个相应位置的字符不同  i与j之间的距离就是几  求连接全部卡车的最短长度  题目不是这个意思  这样理解即可了

prim啦啦啦啦

#include<cstdio>
#include<cstring>
using namespace std;
const int N = 2005;
int cost[N], dis[N][N], n, ans;void prim()
{memset(cost, 0x3f, sizeof(cost));cost[1] = -1;int cur = 1, next = 0;for(int i = 1; i < n; ++i){for(int j = 1; j <= n; ++j){if(cost[j] == -1 || cur == j) continue;if(dis[cur][j] < cost[j]) cost[j] = dis[cur][j];if(cost[j] < cost[next]) next = j;}cur = next, next = 0, ans += cost[cur], cost[cur] = -1;}
}int main()
{char s[N][10];while(scanf("%d", &n), n){memset(dis, 0, sizeof(dis));for(int i = 1; i <= n; ++i)scanf("%s", s[i]);for(int i = 1; i <= n; ++i)for(int j = 1; j <= n; ++j)for(int k = 0; k < 7; ++k)if(s[i][k] != s[j][k]) ++dis[i][j];ans = 0;prim();printf("The highest possible quality is 1/%d.\n", ans);}
}
Truck History

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.

Source

CTU Open 2003

POJ 1789 Truck History(最小生成树)相关推荐

  1. poj 1789 Truck History(最小生成树 prim)

    题目:http://poj.org/problem?id=1789 大意:每个卡车都有自己的编号,由七位字母组成 d(to,td) is the distance of the types指t0 和 ...

  2. Kuskal/Prim POJ 1789 Truck History

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

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

    https://vjudge.net/problem/POJ-1789 题意 n个车牌,长度固定为7,车牌与车牌间的距离为不同字母个数.问所有车牌形成一棵树的最小边权和是多少. 分析 最小生成树模板 ...

  4. POJ 1789 Truck History

    最小生成树问题. 给你一组字母序列,问你最有可能的演变,也就是把全部的序列连通所花费最小. 每次派生的花费 取决于两个字符串上 不同的字母个数. 于是两两算出花费,然后Kruskal算最小. #inc ...

  5. 【POJ】【最小生成树】1789 Truck History

    1 思路 题目链接. 最小生成树(MST)问题. 2 代码 代码来自宇宙吾心博客. #include <iostream> #include <limits> #include ...

  6. POJ-1789 Truck History 最小生成树

    计算整个汽车演化过程中所要改变的最少的字符数.改变的字符数的计算方式为1-7位不同位的个数. 代码如下: #include <cstdlib> #include <cstring&g ...

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

    链接: http://poj.org/problem?id=1789 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2213 ...

  8. 【POJ - 1789】【ZOJ - 2158】【SCU - 1832】Truck History (最小生成树)

    题干: Description Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used f ...

  9. poj 1789 TruckHistory 最小生成树 Kruskal、Prim

    题意: n个车牌号,刚开始只有一个车牌,其他车牌都是由一个车牌直接或间接产生,一个车牌到另一个车牌的产生权值是它们之间的数字不同的个数,问产生的最小的边权和,即求最小生成树. Input: 多组数据. ...

  10. poj1789 Truck History(最小生成树)

    2018-3-24 简单的最小生成树问题. 题目大意是: 给你n个字符串,他们的distance就是串中不同字符的个数,要求算出所有串的distance's 最小 sum : #include< ...

最新文章

  1. ios .framework动态库重签名
  2. DNS协议详解及报文格式分析
  3. mysql实例怎么复制_Mysql实例MySQL数据库复制概论
  4. Flutter AnimatedSwitcher 动画切换组件的基本使用
  5. 实战中总结出来的CSS常见问题及解决办法
  6. MacOS 10.14.5单双面打印设置
  7. 【分享帖】国内主流网络信息采集和页面数据抓取工具盘点
  8. 计算机应用基础网课试题及答案2020,2019-2020年度公共课计算机应用基础考试试题附答案(5页)-原创力文档...
  9. 论文笔记5:Noise Reduction of Hyperspectral Imagery Using Hybrid Spatial-Spectral Derivative-Domain Wavel
  10. Oracle数据库字符集问题解决方案大全
  11. LiveData介绍
  12. mysql limit会扫描全表_为什么用了limit还会进行全表扫描?
  13. [Bzoj3640]JC的小苹果
  14. 思科虚拟服务器修改域名,思科域名服务器设置
  15. 外网连接腾讯云mysql
  16. 无法加载文件,因为在此系统上禁止运行脚本。
  17. abp 链接本地mysql_abp vNext 使用Mysql 数据库
  18. Android TV TIF源码阅读笔记
  19. halcon视觉 一维、二维码的区别-@龙熙视觉培训李杰
  20. 以太坊为什要使用幽灵协议?

热门文章

  1. hibernate中cascade和inverse中的设置问题
  2. 【转】图解Sql2005创建分区表的全过程
  3. 使用Intent Filter来响应隐式Intent
  4. 本人教你五分钟学会五笔(不服找我)
  5. arcgis开发笔记【silverlight 发布rest地图服务】
  6. gulp-rev-append md5版本号
  7. pkill -kill -t pts/1
  8. 用 FragmentManager 替换时使用 GoogleMaps 崩溃 app
  9. 学用MVC4做网站:序
  10. 汪洋大海中的一块绿地