Truck History(卡车历史)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 26547 | Accepted: 10300 |
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<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=;
const int inf=maxn*;
int n;
int a[maxn],map[maxn][maxn];
char ch[maxn][];
bool v[maxn];
int bj(int x,int y){
int ret=;
for(int i=;i<;i++)
if(ch[x][i]!=ch[y][i]) ret++;
return ret;
}
void intn(){
for(int i=;i<=n;i++) scanf("%s",ch[i]);
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++)
map[j][i]=map[i][j]=bj(i,j);
}
int prim(){
memset(v,,sizeof(v));
int ans=,p,b;
v[]=;
for(int i=;i<=n;i++) a[i]=map[][i];
for(int m=;m<n;m++){
p=inf;
for(int i=;i<=n;i++) if(a[i]<p&&!v[i]){p=a[i];b=i;}
ans+=a[b];v[b]=;
for(int i=;i<=n;i++) a[i]=min(a[i],map[b][i]);
}
return ans;
}
int main(){
while(scanf("%d",&n)){
if(!n) break;
else intn();
printf("The highest possible quality is 1/%d.\n",prim());
}
return ;
}
之前的prim打的丑,poj一直给我TLE(只有TLE),果然poj逼格这么高的地方不适合我这样不会英语,又很娇弱的蒟蒻。
题目来源:POJ
Truck History(卡车历史)的更多相关文章
- poj 1789 Truck History【最小生成树prime】
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21518 Accepted: 8367 De ...
- POJ 1789 -- Truck History(Prim)
POJ 1789 -- Truck History Prim求分母的最小.即求最小生成树 #include<iostream> #include<cstring> #incl ...
- History(历史)命令用法
如果你经常使用 Linux 命令行,那么使用 history(历史)命令可以有效地提升你的效率.本文将通过实例的方式向你介绍 history 命令的用法. 使用 HISTTIMEFORMAT 显示时间 ...
- 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 ...
- History(历史)命令用法15例
导读 如果你经常使用 Linux 命令行,那么使用 history(历史)命令可以有效地提升你的效率,本文将通过实例的方式向你介绍 history 命令的 15 个用法. 使用 HISTTIMEFOR ...
- POJ 1789 Truck History (最小生成树)
Truck History 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/E Description Advanced Carg ...
- Truck History(kruskal+prime)
Truck History Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Tota ...
随机推荐
- (进制)51NOD 1057 N的阶乘
输入N求N的阶乘的准确值. Input 输入N(1 <= N <= 10000) Output 输出N的阶乘 Input示例 5 Output示例 120解:这其实是MOD进制,将一个 ...
- C头文件中尖括号与双引号的区别及编译搜索顺序
这两天被问到一个很有意思的问题:C头文件中尖括号与双引号有什么区别,以前只大约知道 <> 常用在系统库文件,"" 常用在自定义的借口文件中,那具体在gcc编译搜索过程中 ...
- C#将类对象转换为字典
主要是实现将类里面 的属性和对应的值转换为字典的键和值. public class RDfsedfw { /// <summary> /// 将匿名类转换为字典 /// </summ ...
- Android 性能优化(13)网络优化( 9)Determining and Monitoring the Docking State and Type
Determining and Monitoring the Docking State and Type PreviousNext This lesson teaches you to Determ ...
- JS数组、数组和学生对象
<html> <head> <meta charset="utf-8"> <title>JS</title> </ ...
- Quartz.Net学习笔记(1)-完整的例子
一.开发环境 系统:Win10 编译器:VS2013 .Net版本:4.5 Quartz版本:2.3.3 二.涉及程序集 Common.Logging.Core.dll Common.Logging. ...
- web开发----jsp中通用模版的引用 include的用法
1.静态引入的示例 通过对两种用法的了解之后 我们现在 使用静态引入 因为上述原因 我的模版页中 只有div 不会有 path等定义 也不会有html标签 如下: 我的header.jsp 全 ...
- IDEA破解方法以及快捷键大全
IntelliJ IDEA2017.3 激活 - CSDN博客:https://blog.csdn.net/dc2222333/article/details/78582131 Eclipse和Int ...
- oracle性能优化培训总结
- 常见Z纯CSS小样式合集(三角形)
三角形 .sanjiao{ width:0px; height: 0px; overflow: hidden; border-width: 100px; border-color: transpare ...