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 ...
随机推荐
- 12.0&12.1 Xcode开发包
12.1开发包下载链接 12.0开发包下载链接 12.1(16B91)开发包下载链接 Finder打开后,按command+shift+G前往这个地址: /Applications/Xcode.app ...
- android黑科技系列——爆破一款应用的签名验证问题
一.前言 在之前的文章中说过Android中的安全和破解是相辅相成的,为了防止被破解,很多应用做了一些防护策略,但是防护策略也是分等级,一般简单的策略就是混淆代码和签名校验,而对于签名校验很多应用都是 ...
- Deutsch lernen (09)
1. die Rückmeldung, -en 反馈,回馈:(销假)报到 die Rückmeldung zur Arbeit 2. dringend a. 紧急的,急切的 Ich brauche d ...
- dubbo之分组聚合
按组合并返回结果 ,比如菜单服务,接口一样,但有多种实现,用group区分,现在消费方需从每种group中调用一次返回结果,合并结果返回,这样就可以实现聚合菜单项. 相关代码可以参考 dubbo 项目 ...
- 【sqli-labs】 less34 POST- Bypass AddSlashes (POST型绕过addslashes() 函数的宽字节注入)
还是宽字节注入,POST版本的 uname=1&passwd=1%df' union select 1,2,3# 提交报错 列名不匹配,改一下就好了 uname=1&passwd=1% ...
- Cache-Control 机制是为浏览器定制的?
Cache-Control 机制是为浏览器定制的?
- MVC返回400 /404/...
return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //HttpStatusCode statusCode 枚举 // HttpSt ...
- spring-boot启动自动执行sql文件失效 解决办法
在springboot1.5及以前的版本,要执行sql文件只需在applicaion文件里指定sql文件的位置即可.但是到了springboot2.x版本, 如果只是这样做的话springboot不会 ...
- Day 20 re模块(正则表达式)
re模块 作用:取文本或者字符串内找你所需要的东西 import re re.findall(参数一,参数二,参数三) #暂时用到前两个,第一个为正则表达式,第二个为字符串,也就是被搜索的文本 ^元字 ...
- vue-属性传值 props
props属性传值 1.传具体的值 string(字符串) number(数值) boolean(布尔) 2.传一个引用 array(数组) object(对象) ----传引用----- 代码 ...