poj 1789 Truck History 解题报告
题目链接: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 解题报告的更多相关文章
- Kuskal/Prim POJ 1789 Truck History
题目传送门 题意:给出n个长度为7的字符串,一个字符串到另一个的距离为不同的字符数,问所有连通的最小代价是多少 分析:Kuskal/Prim: 先用并查集做,简单好写,然而效率并不高,稠密图应该用Pr ...
- POJ 1789 -- Truck History(Prim)
POJ 1789 -- Truck History Prim求分母的最小.即求最小生成树 #include<iostream> #include<cstring> #incl ...
- poj 1789 Truck History
题目连接 http://poj.org/problem?id=1789 Truck History Description Advanced Cargo Movement, Ltd. uses tru ...
- POJ 1789 Truck History【最小生成树简单应用】
链接: http://poj.org/problem?id=1789 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- POJ 1789 Truck History (Kruskal)
题目链接:POJ 1789 Description Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks ...
- poj 1789 Truck History 最小生成树
点击打开链接 Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15235 Accepted: ...
- POJ 1789 Truck History (最小生成树)
Truck History 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/E Description Advanced Carg ...
- poj 1789 Truck History【最小生成树prime】
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21518 Accepted: 8367 De ...
- poj 1789 Truck History 最小生成树 prim 难度:0
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19122 Accepted: 7366 De ...
随机推荐
- Yii 安装学习
(1)打开yii官方网站: http://www.yiichina.com (2)点击下载,跳转到下载页面: (3)找到从归档文件安装,新手学习,使用[ Yii2的基本应用程序模板]: (4)下载解压 ...
- pandaboard安装ubuntu14.04系统遇到的问题
按照该网址步骤安装https://www.eewiki.net/display/linuxonarm/PandaBoard 在linux kernel的./build_kernel.sh时,自动安装交 ...
- python多线程(二)
原文:http://blog.sina.com.cn/s/blog_4b5039210100esc1.html 基础不必多讲,还是直接进入python. Python代码代码的执行由python虚拟机 ...
- .net core mvc启动顺序以及主要部件2
原文:.net core mvc启动顺序以及主要部件2 前一篇提到WebHost.CreateDefaultBuilder(args)方法创建了WebHostBuilder实例,WebHostBuil ...
- jmeter自定义并发用户数图形插件介绍
Stepping Thread Group马上要被废弃了,废弃原因不知道,官方推荐使用 BlazeMeter Inc.公司贡献的插件Concurrency Thread Group,配合 Throug ...
- paddle中新增layer
Implement C++ Class The C++ class of the layer implements the initialization, forward, and backward ...
- 在Nginx上部署ThinkPHP,解决Pathinfo问题
在Nginx上部署ThinkPHP,解决Pathinfo问题 事实上.要解决nginx不支持pathinfo的问题.有两个解决思路,一是不使用pathinfo模式,二是改动nginx的配置文件,使它支 ...
- QVector的内存分配策略
我们都知道 STL std::vector 作为动态数组在所分配的内存被填满时.假设继续加入数据,std::vector 会另外申请一个大小当前容量两倍的区域(假设 n > size 则申请 n ...
- vuex 与 redux 的 区别
一:redux和flux的区别 1)redux是flux中的一个实现 2))在redux中我们只能定义一个store,在flux中我们可以定义多个 3)在redux中,store和dispatch都放 ...
- eclipse 配置执行hadoop 2.7 程序样例參考步骤
前提:你搭建好了hadoop 2.x的linux环境,并可以成功执行.还有就是window可以訪问到集群.over 1. hfds-site.xml 添加属性:关闭集群的权限校验.windows的用户 ...