题目链接:https://vjudge.net/problem/POJ-1789

思路:

题目意思就是说,给定一些长度为7的字符串,可以把字符串抽象为一个点,

每个点之间的距离就是他们本身字符串与其他字符串字符不同的个数。

之后就是一个最小生成树的板子。

 #include <stdio.h>
#include <iostream>
#include <queue>
using namespace std; const int N = (int)2e3+;
const int inf = (int)1e9;
char str[N][];
int g[N][N];
int dis[N];
bool vis[N];
int T; struct node{
int loc;
int w; bool friend operator<(const node& a,const node& b){
return a.w > b.w;
}
}; priority_queue<node > que; int prime(){ for(int i = ; i <= T; i++){
vis[i] = ;
dis[i] = inf;
} while(!que.empty()) que.pop(); que.push(node{,});
dis[] = ; while(!que.empty()){
int u = que.top().loc;
que.pop();
vis[u] = ; for(int v = ; v <= T; v++){
if(!vis[v] && dis[v] > g[u][v]){
dis[v] = g[u][v];
que.push(node{v,dis[v]});
}
}
} int ans = ;
for(int i = ; i <= T; i++)
ans += dis[i]; return ans;
} int main(){ while(scanf("%d",&T)){ if(!T) break; for(int i = ; i <= T; i++)
scanf("%s",&str[i]); int cnt = ;
for(int i = ; i <= T; i++){
for(int j = i + ; j <= T; j++){
cnt = ; //每个点与其他点的距离
for(int o = ; o < ; o++)
if(str[i][o] != str[j][o])
++cnt; g[i][j] = g[j][i] = cnt;
}
} for(int i = ; i <= T; i++)
g[i][i] = ;
/*
for(int i = 1; i <= T; i++){
for(int j = 1; j <= T; j++)
printf("%d ",g[i][j]);
printf("\n");
}
*/
printf("The highest possible quality is 1/%d.\n",prime());
} return ;
}

Truck History POJ - 1789的更多相关文章

  1. (最小生成树)Truck History --POJ -- 1789

    链接: http://poj.org/problem?id=1789 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2213 ...

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

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

  3. F - Truck History - poj 1789

    有一个汽车公司有很多年的汽车制造历史,所以他们会有很多的车型,现在有一些历史学者来研究他们的历史,发现他们的汽车编号很有意思都是有7个小写字母组成的,而且这些小写字母具有一些特别的意义,比如说一个汽车 ...

  4. Truck History POJ - 1789 板子题

    #include<iostream> #include<cstring> #include<algorithm> #include<stdio.h> u ...

  5. poj 1789 prime

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

  6. poj 1789 Truck History

    题目连接 http://poj.org/problem?id=1789 Truck History Description Advanced Cargo Movement, Ltd. uses tru ...

  7. POJ 1789 Truck History【最小生成树简单应用】

    链接: http://poj.org/problem?id=1789 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  8. Kuskal/Prim POJ 1789 Truck History

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

  9. POJ 1789 -- Truck History(Prim)

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

随机推荐

  1. 谷歌浏览器安装JsonView插件

    可方便阅读json格式文件,参考https://www.jianshu.com/p/6ea9f2245f4d

  2. Jenkins+Jmeter配置(Linux环境)

    1.安装jenkins. 1.1在Linux服务器上,必须先安装jdk与Tomcat, 在/opt/tools/tomcat 安装解压Tomcat 1.2.在Linux服务器上安装jmeter 在/o ...

  3. Pwnable-bof

    Download : http://pwnable.kr/bin/bof Download : http://pwnable.kr/bin/bof.c 下载之后,先看看c源码 #include < ...

  4. Appium自动化测试之微信h5元素识别和代码实战

    总会有人问微信的自动化测试怎么做.其实我不太明白,为啥你要对ta做自动化测试啊,除非你们公司产品是基于微信做的开发否则没必要.即使一个公众号我也觉得没必要做自动化测试,基本功能点下没问题就可以了,毕竟 ...

  5. layui中form表单渲染的问题

    layui 官网的这部分文档介绍:http://www.layui.com/doc/modules/form.html#render 注意:针对的是表单元素,input select  textare ...

  6. Vue 使用数组和对象控制Class

    直接上代码: <!doctype html> <html lang="en"> <head> <meta charset="UT ...

  7. FAQ简介

    FAQ:问答系统,Frequently Asked Questions 常见问答系统: FAQ是英文Frequently Asked Questions的缩写,中文意思就是“经常问到的问题”,或者更通 ...

  8. Python中的赋值、深拷贝与浅拷贝(内存地址)

    Python中的赋值.深拷贝与浅拷贝(内存地址) 1.python中的可变对象与不可变对象 (1) 可变对象:dict,list def dict_test(): a = {} b = a print ...

  9. select使用css居右对齐

    select{ direction: rtl; } 下面的方法无效 select{ text-align: right; }

  10. maven pom项目的dependencies转gradle格式

    1.新建一个文件件 2.创建pom.xm,放到新建的文件夹中 3.在命令行切换到新建文件夹中,执行: gradle init --type pom