POJ——T1789 Truck History
http://poj.org/problem?id=1789
Description Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other for furniture, or for bricks. The company has its own code describing each type of a truck. The code is simply a string of exactly seven lowercase letters (each letter on each position has a very special meaning but that is unimportant for this task). At the beginning of company's history, just a single truck type was used but later other types were derived from it, then from the new types another types were derived, and so on.
Today, ACM is rich enough to pay historians to study its history. One thing historians tried to find out is so called derivation plan -- i.e. how the truck types were derived. They defined the distance of truck types as the number of positions with different letters in truck type codes. They also assumed that each truck type was derived from exactly one other truck type (except for the first truck type which was not derived from any other type). The quality of a derivation plan was then defined as Input The input consists of several test cases. Each test case begins with a line containing the number of truck types, N, 2 <= N <= 2 000. Each of the following N lines of input contains one truck type code (a string of seven lowercase letters). You may assume that the codes uniquely describe the trucks, i.e., no two of these N lines are the same. The input is terminated with zero at the place of number of truck types.
Output For each test case, your program should output the text "The highest possible quality is 1/Q.", where 1/Q is the quality of the best derivation plan.
Sample Input 4 Sample Output The highest possible quality is 1/3. Source |
别忘了初始化~
#include <algorithm>
#include <iostream>
#include <cstdio> using namespace std; const int N();
int n,ans;
char s[N][];
int minn,vis[N],d[N],dis[N][N]; void Prime()
{
for(int i=;i<n;i++) d[i]=dis[][i];
d[]=vis[]=;
for(int i=;i<n;i++)
{
minn=;
for(int j=;j<n;j++)
if(!vis[j]&&(!minn||d[minn]<d[j])) minn=j;
vis[minn]=;
for(int j=;j<n;j++)
if(!vis[j]) d[j]=min(d[j],dis[minn][j]);
}
for(int i=;i<n;i++) ans+=d[i];
printf("The highest possible quality is 1/%d.\n",ans); ans=;
} int main()
{
while(scanf("%d",&n)&&n)
{
for(int i=;i<=n;i++)
cin>>s[i];
for(int i=;i<n;i++)
for(int j=i+;j<n;j++)
{
for(int k=;k<;k++)
if(s[i][k]!=s[j][k]) dis[i][j]++;
dis[j][i]=dis[i][j];
}
Prime();
}
return ;
}
POJ——T1789 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 最小生成树
点击打开链接 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 ...
- POJ 1789 Truck History (Kruskal 最小生成树)
题目链接:http://poj.org/problem?id=1789 Advanced Cargo Movement, Ltd. uses trucks of different types. So ...
随机推荐
- bat执行bat文件
目的:在服务器桌面创建一个bat文件执行tomcat下的startup.bat文件,这样就不用每次都去文件夹下找startup.bat文件 桌面bat文件内容: @echo off start D:\ ...
- bram和dram差别
选择distributed memory generator和block memorygenerator标准: Dram和bram差别: 1.bram 的输出须要时钟,dram在给出地址后既可输出数据 ...
- 零基础学python-7.7 字符串格式化方法(1)
承接上一章节.我们这一节来说说字符串格式化的还有一种方法.就是调用format() >>> template='{0},{1} and {2}' >>> templ ...
- HDU 2838 (树状数组求逆序数)
题意: 给你N个排列不规则的数(1~N),任务是把它从小到大排好,每次仅仅能交换相邻两个数,交换一次的代价为两数之和.求最小代价 思路:对于当前数X.我们如果知道前面比它大的数有多少,如果为K,那么有 ...
- Hdu 4280 Island Transport(最大流)
Island Transport Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- Linux程序设计学习笔记——异步信号处理机制
转载请注明出处: http://blog.csdn.net/suool/article/details/38453333 Linux常见信号与处理 基本概念 Linux的信号是一种进程间异步的通信机制 ...
- 51nod-1462: 树据结构
[传送门:51nod-1462] 简要题意: 给出一棵n个点的树,每个点有两个权值v,t 有Q个操作,有两种操作: 1.将x到根上的路径上的点的v值都加上d 2.将x到根上的路径上的点的t值都加上每个 ...
- hdoj--1028--Ignatius and the Princess III(母函数)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- 基于Doxygen的C/C++注释原则
基于Doxygen的C/C++注释原则 标注总述 .文件头标注 . 命名空间标注 . 类.结构.枚举标注 . 函数注释原则 . 变量注释 . 模块标注 . 分组标注 总述 华丽的分隔线 //----- ...
- 关于windows 2008 64位系统驱动的加载问题
三点: 1.bcdedit /set loadoptions DDISABLE_INTEGRITY_CHECKS. 2.bcdedit /set testsigning on. 3.使用X64编译驱动 ...