Truck History POJ - 1789 板子题
2024-09-06 20:22:19
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stdio.h>
using namespace std;
const int INF=0x3f3f3f3f;
const int N=;
int n;
int p[N];
char str[N][];
int num=;
struct edge{
int a,b;
int w;
}e[N*N];
bool cmp(edge a,edge b)
{
return a.w<b.w;
}
int find(int x)
{
if(p[x]!=x)
p[x]=find(p[x]);
return p[x];
}
int dist(int i,int j)
{
int w=;
for(int k=;k<;k++)
if(str[i][k]!=str[j][k])
w++;
return w;
}
int kruskal()
{
sort(e,e+num,cmp);
int sum=;
for(int i=;i<num;i++)
{
int a=find(e[i].a);
int b=find(e[i].b);
int w=e[i].w;
if(a!=b)
{
p[a]=b;
sum+=w;
}
}
return sum;
}
int main()
{
while(cin>>n&&n)
{
num=;
for(int i=;i<=n;i++)
p[i]=i;
for(int i=;i<=n;i++)
cin>>str[i];
for(int i=;i<=n-;i++)
for(int j=i+;j<=n;j++)
e[num++]={i,j,dist(i,j)};
cout<<"The highest possible quality is 1/"<<kruskal()<<'.'<<endl;
}
}
最新文章
- 【BZOJ2223/3524】[Coci 2009]PATULJCI
- BizTalk 中使用 WCF-OracleDB adapter
- Java RESTful Web Service相关概念
- POJ3687——Labeling Balls(反向建图+拓扑排序)
- 汉企C#面向对象——继承
- ADO.NET(一) 空间 ADO.NET结构 命名空间(车延禄) System.Data—— 所有的一般数据访问类 S(转载)
- sql常用语句汇总
- Redis sentinel 哨兵模式集群方案配置
- Docker容器如何互联
- Vivado怎么使用In system debug(类似于chipscope的东西)
- xpath 笔记
- 得到一个文件夹中所有文件的名称的几个方法(命令指示符, C++, python)
- Linux学习笔记之五————Linux常用命令之用户、权限管理
- 【QT】对话框打开图像并用QPixmap显示
- 学习笔记之Lazy evaluation
- wkhtmtopdf--高分辨率HTML转PDF(二)
- 记录pytorch的几个问题
- Android Emoji兼容包使用详解
- 实战入侵(突破FCK+安全狗上传)
- spark第十篇:Spark与Kafka整合