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 ...
随机推荐
- Linux的那点事
1.重启nginx服务器 注意,修改了nginx配置文件后最好先检查一下修改过的配置文件是否正确,以免重启后Nginx出现错误影响服务器稳定运行. 判断Nginx配置是否正确命令如下: nginx - ...
- 初次尝试PHP——一个简单的对数据库操作的增删改查例子
第一次学习PHP,很多人说PHP是最好的语言,学习了一点点,还不敢说这样的话,不过确实蛮好用的. 做了一个简单的对数据库的增删改查的操作,主要是将四种操作写成了独立的函数,之后直接调用函数.以下是代码 ...
- 用SQL Server查询所有数据并显示
利用SQL Server查询数据,并把所有数据显示在页面上. "%> <%@page import="jdbc.sqlServer"%> <%@p ...
- 实验8 标准模板库STL
一.实验目的与要求: 了解标准模板库STL中的容器.迭代器.函数对象和算法等基本概念. 掌握STL,并能应用STL解决实际问题. 二.实验过程: 完成实验8标准模板库STL中练习题,见:http:// ...
- Linux各发行版配置总结
Ubuntu 14.04(该版本下亲测好用) 1.修改开机启动项和默认启动项 sudo gedit /boot/grub/grub.cfg(修改前最好备份一个) 2.登陆界面图片的修改 /usr/sh ...
- Type inference
Type inference refers to the automatic detection of the data type of an expression in a programming ...
- javaee IO流作业02
package Zy; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.Fil ...
- 【转载】Java 集合详解
转载:https://www.cnblogs.com/ysocean/p/6555373.html 一.集合的由来 通常,我们的程序需要根据程序运行时才知道创建多少个对象.但若非程序运行,程序开发阶段 ...
- eoLinker上线两周年+ AMS V4.0 发布:全新UI界面,带来领先的API开发管理解决方案!
2018年7月,eoLinker 发布了<eoLinker AMS 2018年年中用户调研问卷>,前后经历一周的时间,共收集到超过1000份有效调查问卷.超过300个有效改进意见. eoL ...
- php如何判断SQL语句的查询结果是否为空?
PHP与mysql这对黄金搭档配合的相当默契,但偶尔也会遇到一些小需求不知道该怎么做,例如今天要谈到的:如何判断sql语句查询的结果集是否为空! 我们以查询学生信息为例,来看看究竟如何实现我们的需求. ...