给定N个字符串,某个字符串转为另一个字符串的花费为他们每一位不相同的字符数。 求最小花费Q。

Input

多组输入,以0结束。 保证N不超过2000。

Output

每组输出"The highest possible quality is 1/Q."。

Sample Input

4
aaaaaaa
baaaaaa
abaaaaa
aabaaaa
0

Sample Output

The highest possible quality is 1/3.

由于是完全图,所以用prim

1.strlen或者str.length最好用int强制转化一下,要追求0warning

2.distance函数是里面的,不要再include它了

3.判断相等要敲两个等号.

4.'int' is not a class, struct, or union type如果出了这种bug基本就是命名空间混淆了.


#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <bitset>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define ll long long
#define mm0(a) memset(a,0,sizeof(a))
#define mm(a,b) memset(a,b,sizeof(a))
#define each(a,b,c) for(int a=b;a<=c;a++)
#define de(x) cout << #x << " " << (x) <<endl
//#define de(x) cout <<""
#define rush() int T;scanf("%d",&T);each(kase,1,T)
#define scan(a,b) scanf("%d%d",&a,&b)
#define fin(a) scanf("%d",&a)
#include <iostream> using namespace std; //const int maxn = 400+5;
const int maxn = 2e3+5;
const int INF = 0x3f3f3f3f;
inline int read(){int s=0;char ch=getchar();for(; ch<'0'||ch>'9'; ch=getchar());for(; ch>='0'&&ch<='9'; ch=getchar())s=s*10+ch-'0';return s;} bool vis[maxn];
int lowc[maxn];
int Prim(int cost[][maxn],int n)
{
int ans=0;
memset(vis,false,sizeof(vis));
vis[0]=true;//从0开始的
for(int i=1;i<n;i++)lowc[i]=cost[0][i];
for(int i=1;i<n;i++)
{
int minc=INF;
int p=-1;
for(int j=0;j<n;j++)
{
if(!vis[j]&&minc>lowc[j])
{
minc=lowc[j];
p=j;
}
}
//de(minc);
if(minc==-1)return -1;//又把==敲成一个等号了
ans+=minc;
vis[p]=true;
for(int j=0;j<n;j++)
{
if(!vis[j]&&lowc[j]>cost[p][j])
lowc[j]=cost[p][j];
} }
return ans;
}
char str[maxn][8];
int cost[maxn][maxn];
int dist(int i,int j)
{
int ans=0;
for(int k=0;k<7;k++)///这里
{
if(str[i][k]!=str[j][k])
ans++;
}
return ans;
}
/*
4
aaaaaaa
baaaaaa
abaaaaa
aabaaaa
0
*/
int main()
{
int m;
while(scanf("%d",&m)!=EOF&&m!=0)
{
//getchar();//吃掉回车
for(int i=0;i<m;i++)
cin>>str[i];
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
if(i==j)
{
cost[i][j]=0;
}
else
cost[i][j]=dist(i,j);
//de(cost[i][j]);
}
} int ans=Prim(cost,m);
//de(ans);
printf("The highest possible quality is 1/%d.\n",ans); }
}

POJ 1789 Prim的更多相关文章

  1. Truck History - poj 1789 (Prim 算法)

      Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 20884   Accepted: 8075 Description Ad ...

  2. Kuskal/Prim POJ 1789 Truck History

    题目传送门 题意:给出n个长度为7的字符串,一个字符串到另一个的距离为不同的字符数,问所有连通的最小代价是多少 分析:Kuskal/Prim: 先用并查集做,简单好写,然而效率并不高,稠密图应该用Pr ...

  3. POJ 1789 -- Truck History(Prim)

     POJ 1789 -- Truck History Prim求分母的最小.即求最小生成树 #include<iostream> #include<cstring> #incl ...

  4. poj 1789 prime

    链接:Truck History - POJ 1789 - Virtual Judge  https://vjudge.net/problem/POJ-1789 题意:先给出一个n,代表接下来字符串的 ...

  5. POJ 1789 Truck History (Kruskal)

    题目链接:POJ 1789 Description Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks ...

  6. Poj(1789),最小生成树,Prim

    题目链接:http://poj.org/problem?id=1789 还是套路. #include <stdio.h> #include <string.h> #define ...

  7. POJ 1789:Truck History(prim&amp;&amp;最小生成树)

    id=1789">Truck History Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17610   ...

  8. POJ 1789 Truck History(Prim+邻接矩阵)

    ( ̄▽ ̄)" #include<iostream> #include<cstdio> #include<cstring> #include<algo ...

  9. poj 1789 Truck History 最小生成树 prim 难度:0

    Truck History Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19122   Accepted: 7366 De ...

随机推荐

  1. vue实现购物清单列表添加删除

    vue实现购物清单列表添加删除 一.总结 一句话总结: 基础的v-model操作,以及数组的添加(push)删除(splice)操作 1.checkbox可以绑定数组,也可以直接绑定值? 绑定数组就是 ...

  2. [GIT]比较不同分支的差异

        比如我们有 2 个分支:master, dev,现在想查看这两个 branch 的区别,有以下几种方式: undefined 1.查看 dev 有,而 master 中没有的: 1.查看 de ...

  3. Vue于React特性对比(四)

    新开了一个vue的项目,从vue单页面框架搭建到单点登录接入都是自己负责搞的.然后准备将这套东西迁移到react上.然后有了这篇文章. 1,reactjs分环境打包明显要比vue更为麻烦 vue修改的 ...

  4. 通过OpenCL内核代码猜测设备寄存器个数

    在OpenCL标准中,没有给出查看计算设备一共有多少寄存器,至少能分配给每个work-item多少寄存器使用的特征查询.而由于一个段内核代码是否因寄存器紧缺而导致性能严重下降也是一个比较重要的因素,因 ...

  5. Swagger下载的zip文件无法打开,而且大小比直接下载的要大

    以前写的一个rest提供的是浏览器下载zip包的功能,前端界面调用rest可以正常地下载. 今天使用Swagger来调试下载功能时,发现下载的zip包打不开,而且大小也比直接在浏览器中输入rest地址 ...

  6. lnmp搭建-手动版

    参照链接:http://blog.csdn.net/bravemelon/article/details/64925499 centOS 下安装 Nginx yum -y groupinstall & ...

  7. 服务器watchdog看门狗的理解

    1.什么是watchdog?watchdog,中文名称叫做“看门狗”,全称watchdog timer,从字面上我们可以知道其实它属于一种定时器.然而它与我们平常所接触的定时器在作用上又有所不同.普通 ...

  8. glide包管理工具

    上一篇文章中我们已经成功的运行了go的代码,这是我们迈出的最基础的一步. 一个项目通常会依赖很多外部的库,当依赖的库比较多的时候,手工管理就会比较麻烦,这个时候就需要包管理工具出场了,帮你管理好所有依 ...

  9. QFramework 使用指南 2020(八):Res Kit(2)模拟模式与非模拟模式

    在上一篇,介绍了 Res Kit 的基本使用,相信大家已经体会到了 Res Kit 的简便之处了. 在这一篇,我们试着探讨一下 Res Kit 的设计背后原理. AssetBundle 的不便之处 在 ...

  10. django 之(四) --- 级联|截流

    登陆注册 登陆注册实现 settings.py # redis配置 CACHES = { "default": { "BACKEND": "djang ...