#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. C++ 基础--虚构函数

    virtual 函数 示例代码如下: #include <stdio.h> class base { public: virtual void name(){printf("ba ...

  2. 大延时情况tcp和udp测试

    环境搭建 使能Ubuntu的IPv6转发功能 root@yanhc-Aspire-4738G:/home/yanhc# cat /proc/sys/net/ipv4/ip_forward root@y ...

  3. [Redis-CentOS7]Redis集合操作(四)

    SADD 集合添加 127.0.0.1:6379> SADD bbs discuz.net (integer) 1 127.0.0.1:6379> SADD bbs "tiany ...

  4. 杭电-------2052Picture(C语言)

    #include<stdio.h> int main() { int width, height; int i, j; while (~scanf("%d %d", & ...

  5. Javase-坦克大战小游戏,为什么会出现上方向和左方向的子弹不能发射的情况?检查了好久,有大佬帮帮忙吗,小白睡不着

    //为什么会出现上方向和左方向的子弹不能发射的情况?检查了好久,有大佬帮帮忙吗,小白睡不着 package TanKe.lbl;import java.awt.*;import java.awt.ev ...

  6. React之props、state和render函数的关系

    1.当组件中的state或者props发生改变的的时候,render函数就会被重新执行 2.当父组件的render函数被运行时,它的子组件的render都将被重新运行一次 3.子组件作为父组件里的一个 ...

  7. codewars--js--ten minutes walk

    题目: You live in the city of Cartesia where all roads are laid out in a perfect grid. You arrived ten ...

  8. 多线程笔记 - provider-consumer

    通过多线程实现一个简单的生产者-消费者案例(笔记). 首先定义一个要生产消费的数据类 : public class Data { private String id; private String n ...

  9. 使用PropTypes进行类型检查

    原文地址 1.组件特殊属性——propTypes 对Component设置propTypes属性,可以为Component的props属性进行类型检查. import PropTypes from ' ...

  10. 关于apt-get remove 与 apt-get purge

    今天在Ubuntu服务器上安装supervisor,部署没成功想卸载重来,sudo apt-get remove supervisor 后发现配置文件还在,便手动删除了配置文件.再次安装,提示配置文件 ...