Truck History(最小生成树)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 27703 | Accepted: 10769 |
Description
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.
Input
Output
Sample Input
4 aaaaaaa baaaaaa abaaaaa aabaaaa 0
Sample Output
The highest possible quality is 1/3.
Source
#include<cstdlib>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 2001
using namespace std;
struct Edge
{
int x,y,z;
}edge[N*N];
int n,m,fa[N],ans,sum,tot;
];
int cmp(Edge a,Edge b)
{
return a.z<b.z;
}
int found(int x)
{
return fa[x]==x?x:fa[x]=found(fa[x]);
}
int main()
{
while(scanf("%d",&n),n)
{
memset(a,,sizeof(a));
ans=;
;i<=n;i++)
cin>>a[i];
tot=;
;i<n;i++)
;j<=n;j++)
{
sum=;
;k<;k++)
if(a[i][k]!=a[j][k])
sum++;
edge[++tot].x=i;
edge[tot].y=j;
edge[tot].z=sum;
}
sort(edge+,edge++tot,cmp);
;i<=n;i++)
fa[i]=i;
sum=;
;i<=tot;i++)
{
int x=edge[i].x,y=edge[i].y;
int fx=found(x),fy=found(y);
if(fx!=fy)
{
fa[fy]=fx;
sum++;
ans+=edge[i].z;
}
) break;
}
printf("The highest possible quality is 1/%d.\n",ans);
}
;
}
Truck History(最小生成树)的更多相关文章
- poj 1789 Truck History 最小生成树
点击打开链接 Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15235 Accepted: ...
- poj 1789 Truck History 最小生成树 prim 难度:0
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19122 Accepted: 7366 De ...
- poj1789 Truck History最小生成树
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20768 Accepted: 8045 De ...
- POJ 1789 Truck History (最小生成树)
Truck History 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/E Description Advanced Carg ...
- POJ 1789:Truck History(prim&&最小生成树)
id=1789">Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17610 ...
- 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【最小生成树prime】
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21518 Accepted: 8367 De ...
- POJ1789 Truck History 【最小生成树Prim】
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18981 Accepted: 7321 De ...
- poj 1789 Truck History
题目连接 http://poj.org/problem?id=1789 Truck History Description Advanced Cargo Movement, Ltd. uses tru ...
随机推荐
- python爬虫基础14-selenium大全8/8-常见问题
Selenium笔记(8)常见的坑 本文集链接:https://www.jianshu.com/nb/25338984 用Xpath查找数据时无法直接获取节点属性 通常在我们使用xpath时,可以使用 ...
- numpy 三个点的使用[...]
numpy [...]语法简单使用 Python numpy中切片功能与列表切片类似,但功能更加强大 本文主讲numpy中[...]的简单使用,后续工作继续补充. import numpy >& ...
- nRF52-PCA10040——Overview
Overview Zephyr applications use the nrf52_pca10040 board configuration to run on the nRF52 Developm ...
- POJ:1904-King's Quest
King's Quest Time limit15000 ms Case time limit2000 ms Memory limit65536 kB Description Once upon a ...
- HUD:4405-Aeroplane chess(期望飞行棋)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...
- selenium2-框架思想介绍
为什么要有框架? 可维护性 提高编写脚本效率 提高脚本的可读性 框架的几大要素: 1. driver管理 2. 脚本 3. 数据 4. 元素对象 5. Log 6. 报告 7. 运行机制 8. 失败用 ...
- 光学字符识别OCR-8 综合评估
数据验证 尽管在测试环境下模型工作良好,但是实践是检验真理的唯一标准.在本节中,我们通过自己的模型,与京东的测试数据进行比较验证. 衡量OCR系统的好坏有两部分内容:(1)是否成功地圈 ...
- MAC OS X 终端命令入门
在这里记下..防止丢失 pwd 当前工作目录 cd(不加参数) 进root cd(folder) 进入文件夹 cd .. 上级目录 cd ~ 返回root cd - 返回上一个访问的目录 rm 文件名 ...
- Sonar - 部署常见问题及解决方法
1. sonarqube启动报错,查看es.log如下: 问题原因:sonarqube不能使用root用户启动 解决方法: (1)更改sonarqube所属用户权限 chown -R gold:gol ...
- poj1985&&第四次CCF软件认证第4题 求树的直径
Cow Marathon Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 4216 Accepted: 2137 Case ...