题目链接:http://poj.org/problem?id=1789

大意:

不同字符串相同位置上不同字符的数目和是它们之间的差距。求衍生出全部字符串的最小差距。

 #include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int MAXN = ; int cnt;
int pre[MAXN];
char s[MAXN][]; struct Edge
{
int from, to;
int val;
}edge[MAXN * (MAXN - ) / ]; bool cmp(Edge a, Edge b)
{
return a.val < b.val;
} int find(int x)
{
if(pre[x] == x)
return x;
else
{
int root = find(pre[x]);
pre[x] = root;
return pre[x];
}
} int main()
{
int n;
while(scanf("%d", &n) != EOF)
{
if(n == )
break;
getchar();
cnt = ;
for(int i = ; i <= n; i ++)
pre[i] = i;
for(int i = ; i <= n; i ++)
scanf("%s", s[i] + );
for(int i = ; i < n; i ++)
{
for(int j = i + ; j <= n; j ++)
{
int sum = ;
for(int k = ; k <= ; k ++)
if(s[i][k] != s[j][k])
sum ++;
edge[++ cnt].from = i;
edge[cnt].to = j;
edge[cnt].val = sum;
}
}
sort(edge + , edge + + cnt, cmp);
int ans = ;
for(int i = ; i <= cnt; i ++)
{
int xx = find(edge[i].from), yy = find(edge[i].to);
if(xx != yy)
{
pre[yy] = xx;
ans += edge[i].val;
}
}
printf("The highest possible quality is 1/%d.\n", ans);
}
return ;
}

POJ 1789 Truck History【最小生成树模板题Kruscal】的更多相关文章

  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. Kuskal/Prim POJ 1789 Truck History

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

  4. POJ 1789 -- Truck History(Prim)

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

  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(最小生成树)

    模板题 题目:http://poj.org/problem?id=1789 题意:有n个型号,每个型号有7个字母代表其型号,每个型号之间的差异是他们字符串中对应字母不同的个数d[ta,tb]代表a,b ...

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

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

  9. poj 1789 Truck History【最小生成树prime】

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

  10. POJ 1789 Truck History (Kruskal)

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

随机推荐

  1. sql server 存储过程的详解

    SqlServer存储过程详解 1.创建存储过程的基本语法模板: if (exists (select * from sys.objects where name = 'pro_name')) dro ...

  2. struts1 action之间的跳转

    ActionForward actionForward = new ActionForward(); actionForward.setPath("xxxxxxxx");//跳转的 ...

  3. 內嵌html字符串顯示

    前端:System.Web.HttpUtility.HtmlEncode()            @Html.Raw(htmlStr) 後端:System.Net.WebUtility.HtmlDe ...

  4. Java进阶知识19 Struts2和Spring整合在一起

    1.概述 1.Spring负责对象创建  2.Struts2负责用Action处理请求  3.整合的关键点:让Struts2框架Action对象的创建交给Spring完成. 2.整合实例 需要用到的 ...

  5. 51nod 1076

    * 无向图的割边将图分为不连通的两部分 * 对于是否有不想交的两条路径将s -> t 相连 * 只需判断是否处于同一部分 * Tarjan即可 #include <bits/stdc++. ...

  6. MySQL数据分析-(15)表补充:存储引擎

    大家好,我是jacky,很高兴继续跟大家分享<MySQL数据分析实战>,今天跟大家分享的主题是表补充之存储引擎: 我们之前学了跟表结构相关的一些操作,那我们看一下创建表的SQL模型: 在我 ...

  7. Spring Cloud Config(一):聊聊分布式配置中心 Spring Cloud Config

    目录 Spring Cloud Config(一):聊聊分布式配置中心 Spring Cloud Config Spring Cloud Config(二):基于Git搭建配置中心 Spring Cl ...

  8. Python __dict__和vars()

    1 __dict__ 设想这样一个场景.有一个字典,从某个地方获取的,比如http请求发过来的,比如从redis中hgetall出来的.我要根据这个字典来构建一个对象. 比如类 class Perso ...

  9. gdb常用的调试命令

    首先将源代码编译.链接生成debug版本的可执行文件,然后通过‘gdb  debug版本的可执行文件名’进入调试模式. a) 单进程.单线程基础调试命令 l    显示main函数所在的文件的源代码 ...

  10. 飞行姿态角度表示: heading pitch roll

    //创建初始化摄像机视图 var initialPosition=new Cesium.Cartesian3.fromDegrees(-73.998114468289017509, 40.674512 ...