POJ1789 Truck History 2017-04-13 12:02 33人阅读 评论(0) 收藏
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 27335 | Accepted: 10634 |
Description
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.
Input
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.
Output
Sample Input
4
aaaaaaa
baaaaaa
abaaaaa
aabaaaa
0
Sample Output
The highest possible quality is 1/3.
Source
——————————————————————————————————————
题目的意思是给出n个7位字符串,有一个派生到另一个需要花费两个字符串向相应位置不同字母个数,求最小花费
思路:以不同字母个数建边,最小生成树
#include <iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
#define LL long long struct node
{
int u,v,w;
} p[10000005];
int n,cnt,pre[2006];
bool cmp(node a,node b)
{
return a.w<b.w;
}
void init()
{
for(int i=0; i<2005; i++)
pre[i]=i;
} int fin(int x)
{
return pre[x]==x?x:pre[x]=fin(pre[x]);
} void kruskal()
{
sort(p,p+cnt,cmp);
init();
int cost=0;
int ans=0;
for(int i=0; i<cnt; i++)
{
int a=fin(p[i].u);
int b=fin(p[i].v);
if(a!=b)
{
pre[a]=b;
cost+=p[i].w;
ans++;
}
if(ans==n-1)
{
break;
}
}
printf("The highest possible quality is 1/%d.\n",cost);
} int main()
{
char a[2005][10];
while(~scanf("%d",&n)&&n)
{ for(int i=0;i<n;i++)
scanf("%s",&a[i]);
cnt=0;
for(int i=0; i<n; i++)
for(int j=i+1; j<n; j++)
{
int cc=0;
for(int k=0;k<7;k++)
if(a[i][k]!=a[j][k])
cc++;
p[cnt].u=i,p[cnt].v=j;
p[cnt++].w=cc;
}
kruskal();
}
return 0;
}
POJ1789 Truck History 2017-04-13 12:02 33人阅读 评论(0) 收藏的更多相关文章
- 棋盘问题 分类: 搜索 POJ 2015-08-09 13:02 4人阅读 评论(0) 收藏
棋盘问题 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28474 Accepted: 14084 Description 在一 ...
- winfrom 截屏、抓屏 分类: WinForm 2014-08-01 13:02 198人阅读 评论(0) 收藏
截取全屏代码: try { this.Hide(); Rectangle bounds = Screen.GetBounds(Screen.GetBounds(Point.Empty)); Bitma ...
- Hdu1969 Pie 2017-01-17 13:12 33人阅读 评论(0) 收藏
Pie Time Limit : 5000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissio ...
- 【Heritrix基础教程之2】Heritrix基本内容介绍 分类: B1_JAVA H3_NUTCH 2014-06-01 13:02 878人阅读 评论(0) 收藏
1.版本说明 (1)最新版本:3.3.0 (2)最新release版本:3.2.0 (3)重要历史版本:1.14.4 3.1.0及之前的版本:http://sourceforge.net/projec ...
- ZOJ3770Ranking System 2017-04-14 12:42 52人阅读 评论(0) 收藏
Ranking System Time Limit: 2 Seconds Memory Limit: 65536 KB Few weeks ago, a famous software co ...
- ios UIKit动力 分类: ios技术 2015-07-14 12:55 196人阅读 评论(0) 收藏
UIkit动力学是UIkit框架中模拟真实世界的一些特性. UIDynamicAnimator 主要有UIDynamicAnimator类,通过这个类中的不同行为来实现一些动态特性. 它一般有两种初始 ...
- Log4j 2使用教程 分类: B1_JAVA 2014-07-01 12:26 314人阅读 评论(0) 收藏
转载自 Blog of 天外的星星: http://www.cnblogs.com/leo-lsw/p/log4j2tutorial.html Log4j 2的好处就不和大家说了,如果你搜了2,说明你 ...
- Python获取当前时间 分类: python 2014-11-08 19:02 132人阅读 评论(0) 收藏
Python有专门的time模块可以供调用. <span style="font-size:14px;">import time print time.time()&l ...
- Hdu 1009 FatMouse' Trade 2016-05-05 23:02 86人阅读 评论(0) 收藏
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
随机推荐
- Python DB
#!/usr/bin/python #_*_ coding:utf-8 _*_ import MySQLdb import time import threading import random fr ...
- thinkpad t420安装debian需要注意的细节
关闭双显卡,使用集成显卡,32位可以用独显跑起来,但是64位的wheezy只能兼容集成显卡,不知道为啥,否则会在某些usb插入/或者拔出来以后,重启提示 failed to execute /lib/ ...
- springboot的interceptor(拦截器)的应用
一.SpringMVC 中的Interceptor 拦截器也是相当重要和相当有用的,它的主要作用是拦截用户的请求并进行相应的处理.在web开发中,拦截器是经常用到的功能.它可以帮我们验证是否登陆.预先 ...
- HTTP协议响应头之Transfer-Encoding:分块传输详解
Http Connection有两种连接方式:短连接和长连接:短连接即一次请求对应一次TCP连接的建立和销毁过程,而长连接是多个请求共用同一个连接这样可以节省大量连接建立时间提高通信效率.目前主流浏览 ...
- springboot 默认错误处理--自定义
1.在resoures下创建resoures/error文件夹 在其中自定义:404.html 403.html 500.html
- javascript 对象的扩展性
javascript 对象 的可扩展性 javascript 对象中的可扩展性指的是:是否可以给对象添加新属性.所有的内置对象和自定义对象显示的都是可扩展的,对于宿主对象,则有javascript 引 ...
- Symfony 2.0 认识Request, Response, Session, Cookie
在上一节中,我们提到了如何创建一个Bunlde 并且在默认控制器中添加一些方法.如果有参照之前的说法进行的话,读者很有可能会被提示说 返回的Response对象不能为空.好啦,我们就来研究一下,怎么从 ...
- MySQL半同步复制配置
ansible-playbook -f 3 endpoint/mysql.yml -e "exec=fileConfig" -e "db_action=setAll&qu ...
- testng参数化(提供测试数据)
testng提供测试数据的两个注释:@DataProvide和@Parameter 一.通过testng.xml中设置参数 (实际上testng.xml只是一个名字,可以起任何一个名字,只要是.x ...
- Intellij IDEA 启动项目ClassNotFoundException
博客原文地址:https://blog.csdn.net/wo541075754/article/details/45640267 使用Intellij IDEA 的过程中,新创建的项目启动时报错: ...