F - Truck History
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 2010
using namespace std;
int fa[MAXN];
int n,ans,tot;
char s[MAXN][];
struct nond{
int x,y,z;
}v[MAXN*MAXN];
int cmp(nond a,nond b){
return a.z<b.z;
}
int find(int x){
if(fa[x]==x) return x;
else return fa[x]=find(fa[x]);
}
int main(){
while(scanf("%d",&n)&&n){
for(int i=;i<=n;i++) cin>>s[i];
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++){
int sum=;
for(int k=;k<;k++)
if(s[i][k]!=s[j][k]) sum++;
v[++tot].x=i;v[tot].y=j;v[tot].z=sum;
}
sort(v+,v++tot,cmp);
for(int i=;i<=n;i++) fa[i]=i;
for(int i=;i<=tot;i++){
int dx=find(v[i].x);
int dy=find(v[i].y);
if(dx==dy) continue;
fa[dy]=dx;
ans+=v[i].z;
}
printf("The highest possible quality is 1/%d.\n",ans);
ans=;tot=;
}
}
F - Truck History的更多相关文章
- F - Truck History - poj 1789
有一个汽车公司有很多年的汽车制造历史,所以他们会有很多的车型,现在有一些历史学者来研究他们的历史,发现他们的汽车编号很有意思都是有7个小写字母组成的,而且这些小写字母具有一些特别的意义,比如说一个汽车 ...
- POJ 1789:Truck History(prim&&最小生成树)
id=1789">Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17610 ...
- 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 ...
随机推荐
- iWatch报错: Authorization request cancled
iWatch报错: Optional (Error Domin = com.apple.healthkit Code = 5 "Autherization request canceled& ...
- linux下nmap工具的使用
NMap,也就是Network Mapper,是Linux下的网络扫描和嗅探工 具包,其基本功能有三个,一是探测一组主机是否在线:其次是扫描主机端口,嗅探所提供的网络服务:还可以推断主机所用的操作系统 ...
- AJAX复习笔记
AJAX 是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术.通过在后台与服务器进行少量数据交换,AJAX 可况下更新以使网页实现异步更新. 工作原理: AJAX是基于现有的Internet ...
- A - Vile Grasshoppers
Problem description The weather is fine today and hence it's high time to climb the nearby pine and ...
- 取消页面按钮的enter按下事件
<script src="../../@Javascript/jquery-1.8.1.js"></script> <script lan ...
- WPF全球化与本地化
当一个App需要推出多语言版本时,就需要使用到[全球化与本地化]服务. 原理及过程 资源文件中包含了所有的控件信息,通过导出这些控件信息,修改其对应的相关属性(比如TextBlock的Text属性)的 ...
- js 找数组中的最值
背景: 2个数组以下 , 比如 [[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]] 找最值的时候, ...
- Python编程Web框架 :Django 从入门到精通
Django是一个高级别的Python Web框架,它鼓励快速开发和干净实用的设计. 现在我们开始学习它. Django学习之 第一章:Django介绍 Django学习之 第二章:Django快速上 ...
- WPF自定义动画控件 风机
一:创建WPF项目 二:在项目下添加文件Themes,在此文件下添加新项 ”资源词典“取名为 Generic.xaml 注意大小写,之前遇到因为大小写不对应,导致出错的情况Generic.xam ...
- Django[pronounced dʒ] installation on windows
1.Install python, download python windows installer from http://www.python.org/download/ and do inst ...