最小生成树,主要是题目比较难懂。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; const int Maxn=+;
const int maxn=*+;
int Father[Maxn];
struct Edge
{
int from,to,w;
}edge[maxn];
int n,tot;
char s[maxn][]; int Find(int x)
{
if(x!=Father[x]) Father[x]=Find(Father[x]);
return Father[x];
} void init()
{
for(int i=;i<=n;i++) Father[i]=i;
tot=;
} bool cmp(const Edge&a,const Edge&b)
{
return a.w<b.w;
} int main()
{
freopen("in.txt","r",stdin);
while(~scanf("%d",&n)){
if(!n) break;
init();
for(int i=;i<n;i++)
scanf("%s",s[i]); for(int i=;i<n;i++)
for(int j=i+;j<n;j++)
{
edge[tot].from=i;
edge[tot].to=j;
edge[tot].w=;
for(int k=;k<;k++)
if(s[i][k]!=s[j][k])
edge[tot].w++;
tot++;
} sort(edge,edge+tot,cmp); int W=;
for(int i=;i<tot;i++)
{
int Fu=Find(edge[i].from);
int Fv=Find(edge[i].to);
if(Fu!=Fv)
{
Father[Fu]=Fv;
W=W+edge[i].w;
}
}
printf("The highest possible quality is 1/%d.\n",W);}
return ;
}

ZOJ 2158 POJ 1789 Truck History的更多相关文章

  1. Kuskal/Prim POJ 1789 Truck History

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

  2. POJ 1789 -- Truck History(Prim)

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

  3. poj 1789 Truck History

    题目连接 http://poj.org/problem?id=1789 Truck History Description Advanced Cargo Movement, Ltd. uses tru ...

  4. POJ 1789 Truck History【最小生成树简单应用】

    链接: http://poj.org/problem?id=1789 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  5. POJ 1789 Truck History (Kruskal)

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

  6. poj 1789 Truck History 最小生成树

    点击打开链接 Truck History Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15235   Accepted:  ...

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

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

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

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

  9. poj 1789 Truck History 最小生成树 prim 难度:0

    Truck History Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19122   Accepted: 7366 De ...

随机推荐

  1. SSLPinning 延伸

    AFSecurityPolicy用于验证HTTPS请求的证书,先来看看HTTPS的原理和证书相关的几个问题. HTTPS HTTPS连接建立过程大致是,客户端和服务端建立一个连接,服务端返回一个证书, ...

  2. Memcached内存存储

    早就听说过Memcached独特的内存管理方式,写着篇文章的目的就是了解Memcached的内存管理,学习其源代码. 1.什么是Slab Allocator memcached默认情况下采用了名为Sl ...

  3. 自定义viewpager的界面切换动画

    核心操作: 1.创建一个类实现 android.support.v4.view.ViewPager.PageTransformer 根据 position 实现判断哪个界面进行界面切换动画 publi ...

  4. sql 针对多个id或名称的分割和组合

    开发中经常遇到把多个id拼接在一起符号隔开传入数据库,那拆分呢就是个大事 SELECT nPushID INTO #temp FROM Table1 ), nCoulmn) SELECT * FROM ...

  5. sublime 3 增加php开发插件

    1.PHP语法自动完成插件 https://github.com/erichard/SublimePHPCompanion 2.ThinkPHP自动完成插件 https://github.com/ya ...

  6. Jmeter组件介绍

    测试计划:一次性能测试的相关功能用例集. 测试计划--线程组添加:

  7. openstack私有云布署实践【6 RabbitMQ】

    生产环境建议在集群三台controller上做rabbitmq 使用到队列的openstack组件 OpenStack Compute OpenStack Block Storage OpenStac ...

  8. C#_传单小子

    2013/4/13日编写,已经许久不用了,今天又翻出来了,打算继续完善这个小软件,明年将发布出来提供给大家使用.

  9. 2016年团体程序设计天梯赛-决赛 L1-1. 正整数A+B(15)

    本题的目标很简单,就是求两个正整数A和B的和,其中A和B都在区间[1,1000].稍微有点麻烦的是,输入并不保证是两个正整数. 输入格式: 输入在一行给出A和B,其间以空格分开.问题是A和B不一定是满 ...

  10. CKEditor 案例

    官网下载: http://ckeditor.com/download 将下载的ckeditor整个文件放入项目中 在页面中引用ckeditor.js,并用新建一个<textarea>再建一 ...