题目链接: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. python--第四天练习题

    #1.写函数,利用递归获取斐波那契数列中的第 10 个数,并将该值返回给调用者. def rec(a,b,dep=1): c = a + b if dep == 10: return c return ...

  2. P4461 [CQOI2018]九连环

    思路:\(DP\) 提交:\(2\)次 错因:高精写挂(窝太菜了) 题解: 观察可知\(f[i]=2*f[i-1]+(n\&1)\) 高精的过程参考了WinXP@luogu的思路: 发现一个问 ...

  3. 在Ubuntu上安装openResty #1

    在Ubuntu上安装openResty #1 OpenResty® 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库.第三方模块以及大多数的依赖项.用于方 ...

  4. Git入门(待更)

    github是什么? 以下截取自百度百科 github: GitHub 是一个面向开源及私有软件项目的托管平台,因为只支持 Git 作为唯一的版本库格式进行托管,故名 GitHub. GitHub 于 ...

  5. 如何通过Thread查看一个方法被调用的顺序

    Test1 package com.dwz.concurrency.chapter11; public class Test1 { private Test2 test2 = new Test2(); ...

  6. 5.4.1 sequenceFile读写文件、记录边界、同步点、压缩排序、格式

    5.4.1      sequenceFile读写文件.记录边界.同步点.压缩排序.格式 HDFS和MapReduce是针对大文件优化的存储文本记录,不适合二进制类型的数据.SequenceFile作 ...

  7. Ryu控制器安装部署和入门

    Ryu官网简介,原滋原味 Ryu is a component-based software defined networking framework. Ryu provides software c ...

  8. 为什么使用Spring Boot

    原文:https://dzone.com/articles/why-springboot 作者:Siva Prasad Reddy Katamreddy 译者:Oopsguy 本文将介绍各种 Spri ...

  9. 跨域请求错误: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource

    今天在学习Angular 的HttpInterceptor 拦截器时,发现添加了新的headers键值之后总是报跨域错误.后台使用的是asp.net core. 检查发现,在添加了新的header之后 ...

  10. delphi10.3.1不支持.net 5

    delphi10.3.1不支持.net 5 安装DELPHI的前提条件:WINDOWS必须安装有.NET. DELPHI安装程序在安装的时候会自动检测.NET是否已经安装好,如果发现没有,它会报错,并 ...