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

题目意思:给出 N 行,每行7个字符你,统计所有的 行 与 行 之间的差值(就是相同位置下字母不相同),一个位置不相同就为1,依次累加。问最终的差值最少是多少。

额.....题意我是没看懂啦= =......看懂之后,就转化为最小生成树来做了。这是一个完全图,即每条边与除它之外的所有边都连通。边与边的权值是通过这个差值来算出来的。

 #include <iostream>
#include <cstdio>
using namespace std; const int maxn = + ;
const int INF = 1e9;
int truck[maxn][maxn];
int dist[maxn], vis[maxn];
char input[maxn][maxn];
int ans, N; void prim()
{
int k;
for (int i = ; i <= N; i++)
{
vis[i] = ;
dist[i] = INF;
}
dist[] = ;
for (int i = ; i <= N; i++)
{
int tmp = INF;
for (int j = ; j <= N; j++)
{
if (!vis[j] && dist[j] < tmp)
{
tmp = dist[j];
k = j;
}
}
vis[k] = ;
ans += tmp;
for (int j = ; j <= N; j++)
{
if (!vis[j] && dist[j] > truck[k][j])
dist[j] = truck[k][j];
}
}
} int main()
{
while (scanf("%d", &N) != EOF && N)
{
for (int i = ; i <= N; i++)
scanf("%s", &input[i]);
int cnt;
for (int i = ; i < N; i++)
{
for (int j = i+; j <= N; j++)
{
cnt = ;
for (int k = ; k < ; k++)
{
if (input[i][k] != input[j][k])
cnt++;
}
truck[i][j] = truck[j][i] = cnt;
}
}
ans = ;
prim();
printf("The highest possible quality is 1/%d.\n", ans);
}
return ;
}

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. springboot开发 第一个案例之hello,world!

    开发环境:(1)Eclipse Java EE  Version: Neon Release (4.6.0)  Build id: 20160613-1800    (2)apache-maven-3 ...

  2. php——离线执行任务

    <?php//设置忽略是否关闭终端窗口ignore_user_abort(true);ini_set('max_execution_time', '0');//采集页面函数,看不懂执行百度cur ...

  3. linux下将目录授权给其他用户的步骤

    1.更改目录所有者命令:chown -R 用户名称 目录名称2.更改目录权限命令:chmod -R 755 目录名称

  4. hdu 4849

    简单题,公式计算+最短路.注意点:注意1 取模,2 数组开到n*n+n. #include<iostream> #include<queue> using namespace ...

  5. 树莓派LED指示灯说明

    原文:http://shumeipai.nxez.com/2014/09/30/raspberry-pi-led-status-detail.html?variant=zh-cn LED亮灯状态 LE ...

  6. CODEVS_1033 蚯蚓的游戏问题 网络流 最小费用流 拆点

    原题链接:http://codevs.cn/problem/1033/ 题目描述 Description 在一块梯形田地上,一群蚯蚓在做收集食物游戏.蚯蚓们把梯形田地上的食物堆积整理如下: a(1,1 ...

  7. Apache Beam 传 大数据杂谈

    1月10日,Apache软件基金会宣布,Apache Beam成功孵化,成为该基金会的一个新的顶级项目,基于Apache V2许可证开源. 2003年,谷歌发布了著名的大数据三篇论文,史称三驾马车:G ...

  8. Go -- PipleLine

    1.pipeline的产生 从一个现象说起,有一家咖啡吧生意特别好,每天来的客人络绎不绝,客人A来到柜台,客人B紧随其后,客人C排在客人B后面,客人D排在客人C后面,客人E排在客人D后面,一直排到店面 ...

  9. gdb生成的core文件位置

    gdb可以生成core文件,记录堆栈信息,core文件名字是下面这种格式 :core.9488,其中9488是PID 文件位置是当前目录

  10. DICOM医学图像显示算法改进与实现——LUT

    引言 随着Ul(超声成像).CT(计算机断层成像).MRI(核磁共振成像).CR(计算机X线成像).电子内窥镜.盯(正电子发射断层成像)和MI(分子影像)等医学影像设备不断涌现,利用计算机对医学影像设 ...