Truck History --hdoj
Truck History
Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 13 Accepted Submission(s) : 9
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
1/Σ(to,td)d(to,td)
where the sum goes over all pairs of types in the derivation plan such that to is the original type and td the type derived from it and d(to,td)
is the distance of the types.
Since historians failed, you are to write a program to help them. Given the codes of truck types, your program should find the highest possible quality of a derivation plan.
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.
4
aaaaaaa
baaaaaa
abaaaaa
aabaaaa
0
The highest possible quality is 1/3.
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int map[2001][2001];
char str[2000][8];
int mark[2000],t;
int prim()
{ int sum = 0;
int n=t;
int min,k;
memset(mark,0,sizeof(mark));
while(--n)
{
min = 10000;
for (int i = 2; i <= t; i++)
{
if(mark[i]!=1 && map[1][i] < min)
{
min = map[1][i];
k = i;
}
}
mark[k] = 1;
sum += min;
for (int j = 2; j <= t; j++)
{
if(mark[j]!=1 && map[k][j] < map[1][j])
{
map[1][j] = map[k][j];
}
}
}
return sum;
}
int main()
{
while(scanf("%d",&t),t)
{
memset(map,0,sizeof(map));
memset(mark,0,sizeof(mark));
int i,j;
for(i=1;i<=t;i++)
scanf("%s",str[i]);
for(i=1;i<=t;i++)
for(j=i+1;j<=t;j++)
{
for(int k=0;k<7;k++)
{
if(str[i][k]!=str[j][k])
map[i][j]++;
}
map[j][i]=map[i][j];
}
printf("The highest possible quality is 1/%d.\n",prim());
}
}
Truck History --hdoj的更多相关文章
- Truck History(prim & mst)
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19772 Accepted: 7633 De ...
- poj1789 Truck History
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20768 Accepted: 8045 De ...
- poj 1789 Truck History 最小生成树
点击打开链接 Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15235 Accepted: ...
- poj 1789 Truck History
题目连接 http://poj.org/problem?id=1789 Truck History Description Advanced Cargo Movement, Ltd. uses tru ...
- 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 ...
- Truck History(kruskal+prime)
Truck History Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Tota ...
- POJ1789 Truck History 【最小生成树Prim】
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18981 Accepted: 7321 De ...
- Truck History(prime)
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31871 Accepted: 12427 D ...
随机推荐
- JavaScript 判断手机端操作系统(Andorid/IOS)
androidURL = "http://xxx/xxx.apk"; var browser = { versions: function() { var u = navigato ...
- Java创建Excel-DEMO
import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.Out ...
- unicode、UTF-8、UTF-16的历史
1:中国人民通过对 ASCII 编码的中文扩充改造,产生了 GB2312 编码,可以表示6000多个常用汉字. 2:汉字实在是太多了,包括繁体和各种字符,于是产生了 GBK 编码,它包括了 GB231 ...
- 安装rails卡住很慢 出现302 Moved Temporarily
在MAC上安装rails的时候,使用命令$ gem install rails 发现一直没响应,使用$ gem install rails-V命令发现,安装会在中间卡住,出现302 Moved Tem ...
- (转)Bootstrap 之 Metronic 模板的学习之路 - (1)总览
https://segmentfault.com/a/1190000006673582#articleHeader0 写在前面 bootstrap 的模板非常多,Envato 上有着各种各样的免费及付 ...
- pycharm主题 变量颜色 自定义
File--Settings--Edtior--Color Schame-- Lanuage Defaults
- Postgresql_最新版11.2源码编译安装
pg官网:https://www.postgresql.org/ yum -y gcc gcc-c++ cmake ncurses-devel perl zlib* .去官网下载源码包. 下载地址:h ...
- PAT_A1137#Final Grading
Source: PAT A1137 Final Grading (25 分) Description: For a student taking the online course "Dat ...
- UIAutomator定位简介
UIAutomator元素定位是 Android 系统原生支持的定位方式,虽然与 xpath 类似,但比它更加好用,且支持元素全部属性定位.定位原理是通过android 自带的android uiau ...
- 【剑指Offer】4、重建二叉树
题目描述: 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列 ...