POJ 1789 Truck History(最小生成树)
题意 有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);}
}
Description
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
Output
Sample Input
4 aaaaaaa baaaaaa abaaaaa aabaaaa 0
Sample Output
The highest possible quality is 1/3.
Source
POJ 1789 Truck History(最小生成树)相关推荐
- poj 1789 Truck History(最小生成树 prim)
题目:http://poj.org/problem?id=1789 大意:每个卡车都有自己的编号,由七位字母组成 d(to,td) is the distance of the types指t0 和 ...
- Kuskal/Prim POJ 1789 Truck History
题目传送门 题意:给出n个长度为7的字符串,一个字符串到另一个的距离为不同的字符数,问所有连通的最小代价是多少 分析:Kuskal/Prim: 先用并查集做,简单好写,然而效率并不高,稠密图应该用Pr ...
- POJ - 1789 Truck History (最小生成树)
https://vjudge.net/problem/POJ-1789 题意 n个车牌,长度固定为7,车牌与车牌间的距离为不同字母个数.问所有车牌形成一棵树的最小边权和是多少. 分析 最小生成树模板 ...
- POJ 1789 Truck History
最小生成树问题. 给你一组字母序列,问你最有可能的演变,也就是把全部的序列连通所花费最小. 每次派生的花费 取决于两个字符串上 不同的字母个数. 于是两两算出花费,然后Kruskal算最小. #inc ...
- 【POJ】【最小生成树】1789 Truck History
1 思路 题目链接. 最小生成树(MST)问题. 2 代码 代码来自宇宙吾心博客. #include <iostream> #include <limits> #include ...
- POJ-1789 Truck History 最小生成树
计算整个汽车演化过程中所要改变的最少的字符数.改变的字符数的计算方式为1-7位不同位的个数. 代码如下: #include <cstdlib> #include <cstring&g ...
- (最小生成树)Truck History --POJ -- 1789
链接: http://poj.org/problem?id=1789 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 2213 ...
- 【POJ - 1789】【ZOJ - 2158】【SCU - 1832】Truck History (最小生成树)
题干: Description Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used f ...
- poj 1789 TruckHistory 最小生成树 Kruskal、Prim
题意: n个车牌号,刚开始只有一个车牌,其他车牌都是由一个车牌直接或间接产生,一个车牌到另一个车牌的产生权值是它们之间的数字不同的个数,问产生的最小的边权和,即求最小生成树. Input: 多组数据. ...
- poj1789 Truck History(最小生成树)
2018-3-24 简单的最小生成树问题. 题目大意是: 给你n个字符串,他们的distance就是串中不同字符的个数,要求算出所有串的distance's 最小 sum : #include< ...
最新文章
- ios .framework动态库重签名
- DNS协议详解及报文格式分析
- mysql实例怎么复制_Mysql实例MySQL数据库复制概论
- Flutter AnimatedSwitcher 动画切换组件的基本使用
- 实战中总结出来的CSS常见问题及解决办法
- MacOS 10.14.5单双面打印设置
- 【分享帖】国内主流网络信息采集和页面数据抓取工具盘点
- 计算机应用基础网课试题及答案2020,2019-2020年度公共课计算机应用基础考试试题附答案(5页)-原创力文档...
- 论文笔记5:Noise Reduction of Hyperspectral Imagery Using Hybrid Spatial-Spectral Derivative-Domain Wavel
- Oracle数据库字符集问题解决方案大全
- LiveData介绍
- mysql limit会扫描全表_为什么用了limit还会进行全表扫描?
- [Bzoj3640]JC的小苹果
- 思科虚拟服务器修改域名,思科域名服务器设置
- 外网连接腾讯云mysql
- 无法加载文件,因为在此系统上禁止运行脚本。
- abp 链接本地mysql_abp vNext 使用Mysql 数据库
- Android TV TIF源码阅读笔记
- halcon视觉 一维、二维码的区别-@龙熙视觉培训李杰
- 以太坊为什要使用幽灵协议?