题目链接: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. 将vim打造成python开发工具

    1.创建vim插件工作目录 [root@ray ~]# mkdir -p ~/.vim/bundle 2.下载插件 [root@ray ~]# cd ~/.vim/bundle [root@ray b ...

  2. Educational Codeforces Round 72 (Rated for Div. 2) B题

    Problem Description: You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a ...

  3. 第二章实战补充:Python操作Mysql

    ( 一) 导入pymysql 基础铺垫:pymysql与MySQLdb pymysql–支持py2.py3; MySQLdb–仅支持python3; django内部默认为MySQLdb,用Pytho ...

  4. layer 漂亮的弹窗

    layer.confirm('<font color="red">请认真核对账目信息,提交后将不可撤回!!</font>', { icon:3, title ...

  5. 2019腾讯前端技术大会资源TWeb

    扫码关注公众号 回复“TWeb”即可获取“2019腾讯前端技术大会”的PPT

  6. 如何查看appPackage和启动appActivity

    安装apk,模拟器或真机中在前台运行该应用程序,获取appPackage,即应用包名 appPackage:  adb shell dumpsys activity | find "mFoc ...

  7. powerdesigner导出rtf

    报告--reports--新建reports--reports template选择None 从左侧的Available items 拖动 需要导出的item到右侧 右侧的每一个item右键 可以设置 ...

  8. JDBC的工具类

    A: 抽取两个方法,一个获取Connection对象,一个是释放资源 import java.io.FileReader; import java.sql.Connection; import jav ...

  9. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in 解决方案:$sql = ...

  10. pyCharm最新2017激活

    pyCharm最新2017:下载地址 下载完成后安装软件 启动pyCharm,进入下面窗口 选择License server 在 server选项里边输入 http://elporfirio.com: ...