题目链接: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. 彻底搞懂prototype和__proto__

    prototype是函数特有的属性,是Function的静态属性:__proto__是对象特有的属性. 因为函数本身是一种对象,所以函数既有prototype属性也有__proto__属性. 当函数使 ...

  2. Win7下如何安装切换jdk7和jdk8

    一.安装好JDK1.7和1.8. 二.配置环境变量: 1. 创建三个JAVA_HOME.JAVA7_HOME,存放JDK7的安装路径.JAVA8_HOME,存放JDK8的安装路径.JAVA_HOME, ...

  3. 安裝PHPBB

    1.下載PHPBB https://www.phpbb.com/downloads/ 2下載PHP http://windows.php.net/download/ 很多教程都介紹在WIN7用ISAP ...

  4. 富文本编辑器word

    tinymce是很优秀的一款富文本编辑器,可以去官网下载.https://www.tiny.cloud 这里分享的是它官网的一个收费插件powerpaste的旧版本源码,但也不影响功能使用. http ...

  5. leetcode解题报告(6):Remove Duplicates from Sorted List

    描述 Given a sorted linked list, delete all duplicates such that each element appear only once. For ex ...

  6. shell 重定向0,1,2

    .1和2分别表示标准输入.标准输出和标准错误信息输出,可以用来指定需要重定向的标准输入或输出,比如 >a.txt 表示将错误信息输出到文件a.txt中. #将1,2输出转发给/dev/null设 ...

  7. Echarts-复杂关系图(源码)

    关系图: 代码: <!DOCTYPE html> <head> <meta charset="utf-8"> <script type=& ...

  8. Ubuntu start:未知任务:mysql

    在Ubuntu环境下,下载安装mysql但是到最后启动的时候却显示这一句话: start :未知任务:mysql 很纳闷,明明按照教程一步一步写的.后来才想起来,万能的方法,在前面加权限 sudo s ...

  9. jquer属性 offset、position、scrollTop

    尺寸操作 1.获取宽高      a) jq对象.height/width () :只有获取高度/宽度         尺寸,不包括padding和margin 和 border 2.设置宽度     ...

  10. SVN的工作机制

    一.C/S结构 二.基本操作 1. 检出(Checkout)  把服务器端版本库内容完整下载到本地. 2. 更新(Update)  把服务器端相对于本地的新的修改下载到本地. 3. 提交(Comm ...