#include<iostream>
#include<cstring>
#include<algorithm>
#include<stdio.h>
using namespace std;
const int INF=0x3f3f3f3f;
const int N=;
int n;
int p[N];
char str[N][];
int num=;
struct edge{
int a,b;
int w;
}e[N*N];
bool cmp(edge a,edge b)
{
return a.w<b.w;
}
int find(int x)
{
if(p[x]!=x)
p[x]=find(p[x]);
return p[x];
}
int dist(int i,int j)
{
int w=;
for(int k=;k<;k++)
if(str[i][k]!=str[j][k])
w++;
return w;
}
int kruskal()
{
sort(e,e+num,cmp);
int sum=;
for(int i=;i<num;i++)
{
int a=find(e[i].a);
int b=find(e[i].b);
int w=e[i].w;
if(a!=b)
{
p[a]=b;
sum+=w;
}
}
return sum;
}
int main()
{
while(cin>>n&&n)
{
num=;
for(int i=;i<=n;i++)
p[i]=i;
for(int i=;i<=n;i++)
cin>>str[i];
for(int i=;i<=n-;i++)
for(int j=i+;j<=n;j++)
e[num++]={i,j,dist(i,j)};
cout<<"The highest possible quality is 1/"<<kruskal()<<'.'<<endl;
}
}

Truck History POJ - 1789 板子题的更多相关文章

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

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

  2. Truck History - poj 1789 (Prim 算法)

      Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 20884   Accepted: 8075 Description Ad ...

  3. Truck History POJ - 1789

    题目链接:https://vjudge.net/problem/POJ-1789 思路: 题目意思就是说,给定一些长度为7的字符串,可以把字符串抽象为一个点, 每个点之间的距离就是他们本身字符串与其他 ...

  4. F - Truck History - poj 1789

    有一个汽车公司有很多年的汽车制造历史,所以他们会有很多的车型,现在有一些历史学者来研究他们的历史,发现他们的汽车编号很有意思都是有7个小写字母组成的,而且这些小写字母具有一些特别的意义,比如说一个汽车 ...

  5. POJ 1789 Truck History (Kruskal最小生成树) 模板题

    Description Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for v ...

  6. POJ 1789 Truck History【最小生成树模板题Kruscal】

    题目链接:http://poj.org/problem?id=1789 大意: 不同字符串相同位置上不同字符的数目和是它们之间的差距.求衍生出全部字符串的最小差距. #include<stdio ...

  7. poj 1789 prime

    链接:Truck History - POJ 1789 - Virtual Judge  https://vjudge.net/problem/POJ-1789 题意:先给出一个n,代表接下来字符串的 ...

  8. Kuskal/Prim POJ 1789 Truck History

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

  9. poj 1789 Truck History

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

随机推荐

  1. OsgEearh 中的 FeatureEditor的实现原理

    先来看看FeatureEditor的用法: const osgEarth::SpatialReference* mapSRS = mapNode->getMapSRS(); osgEarth:: ...

  2. NR / 5G - The Best CQI algorithm

  3. CentOS7.3yum安装MariaDB报错[Errno 256]

    在yum安装MariaDB时出现下面这个错误提示,然后着手排查,先检查了/etc/yum.repo.d/下的配置文件,没有错误. failure: repodata/repomd.xml from m ...

  4. 多校二 1003Maximum Sequence 模拟

    Maximum Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. python制作ico图标

    import PythonMagick img = PythonMagick.Image('image.png') img.sample('64x64') img.write('image_64x64 ...

  6. zabbix-agent TIME_WAIT 过多(转)

    一.系统环境 操作系统: Centos 6.4 64bit zabbix-agent 版本: Zabbix agent v2.2.7 (revision 50148) (24 October 2014 ...

  7. kali中安装中文输入法ibus

    1.控制台输入命令: apt-get install ibus-pinyin 出现选择都选yes 2.安装完毕后输入命令,重启虚拟机: reboot 3.打开  输入法,如图中2处input meth ...

  8. Mysql数据库操作(命令行)

    1 环境 树莓派: mysql: 2  指令 以下是从命令行中连接mysql服务器的简单实例: [root@host]# mysql -u root -p Enter password:****** ...

  9. Android Vitamio初探

    GitHub: https://github.com/yixia/VitamioBundle 1.下载完毕导入用Android Studio打开 2.新建Mode,引入依赖 dependencies ...

  10. 2020年如何成为一个高级AVA架构师(50W~100W年薪)

    2020年如何成为一个高级AVA架构师(50W~100W年薪)