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 ...
随机推荐
- 李涛ps高手之路
下载地址:http://www.ly89.cn/detailR/21.html
- Python爬取全站妹子图片,差点硬盘走火了!
在这严寒的冬日,为了点燃我们的热情,今天小编可是给大家带来了偷偷收藏了很久的好东西.大家要注意点哈,我第一次使用的时候,大意导致差点坏了大事哈! 1.所需库安装 2.网站分析 首先打开妹子图的官网(m ...
- Counting Cliques HDU - 5952 单向边dfs
题目:题目链接 思路:这道题vj上Time limit:4000 ms,HDU上Time Limit: 8000/4000 MS (Java/Others),且不考虑oj测评机比现场赛慢很多,但10月 ...
- 线段树:POJ3468-A Simple Problem with Integers(线段树注意事项)
A Simple Problem with Integers Time Limit: 10000MS Memory Limit: 65536K Description You have N integ ...
- Phonegap环境配置和安装插件
一:安装好jdk(配置好环境变量) 二:安装好Android SDK(配置好环境变量path F:\Android\android-sdk-windows\platform-tools;F:\Andr ...
- Http协议中的get和post
Http中post和get区别,是不是用get的方法用post都能办到? Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符 ...
- [转] WEB前端学习资源清单
常用学习资源 JS参考与基础学习系列 [MDN]JS标准参考 es6教程 JS标准参考教程 编程类中文书籍索引 深入理解JS系列 前端开发仓库 <JavaScript 闯关记> JavaS ...
- asp.net多线程在web页面中简单使用
需求:一个web页面 default.aspx 里面有两个控件GridView1,GridView2,通过两个线程分别加载绑定数据. 绑定GridView1:void BindCategory() ...
- 简单配置.htaccess就可以实现的10个功能
http://bbs.itcast.cn/thread-25990-1-1.html?xhw 1. 反盗链那些盗用了你的内容,还不愿意自己存储图片的网站是很常见的.你可以通过以下配置来放置别人盗用你的 ...
- bootstrap3兼容ie8浏览器
bootstrap3 兼容IE8浏览器 2016-01-22 14:01 442人阅读 评论(0) 收藏 举报 分类: html5(18) 目录(?)[+] 近期在使用bootstrap这 ...