题目链接: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. 【洛谷P1963】[NOI2009]变换序列(二分图匹配)

    传送门 题意: 现有一个\(0\)到\(n-1\)的排列\(T\),定义距离\(D(x,y)=min\{|x-y|,N-|x-y|\}\). 现在给出\(D(i, T_i)\),输出字典序最小的符合条 ...

  2. Selenium库详解

    Selenium 自动化测试工具,支持多种浏览器 爬虫中解决JS渲染问题

  3. Jmeter+Jenkins的HTML报告中添加QPS、90%栏目显示

    1.进入jmeter/extras目录,修改 jmeter-results-detail-report_21.xsl   2.打开文件 在summary部分修改如下: 在pagelist部分修改如下: ...

  4. Html学习之十六(表格与表单学习--课程表制作)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. day75_10_22频率认证和jwt

    一.频率认证原理. 1.从dispatch中获取配置,找到setting中的配置. 2.从thtoyyling中寻找到各个认证类. 3.所有认证类都继承自basethrottle,basethrott ...

  6. 计算多个点中距离最远的两个点 python

    import numpy as npfrom scipy import spatial print("hello")# test pointspts = np.random.ran ...

  7. 【Spring JDBC】数据源配置(二)

    一.Spring内置数据源 1. 创建Maven Project,修改pom.xml <properties> <!-- JDK版本 --> <java.version& ...

  8. Apex 企业设计模式

    FFLIB 是一个免费的框架,对 Apex 进行了扩展.它的结构实现了 Salesforce 推荐的Apex 企业设计模式. 在学习如何使用 FFLIB 框架之前,我们先来了解一下 Apex 企业设计 ...

  9. cicros安装

    1.下载与安装依赖包 wget https://github.com/libgd/libgd/releases/download/gd-2.2.5/libgd-2.2.5.tar.gz tar zxv ...

  10. pwntools出现的一些问题

    pwntools用的好好的突然就不能用了总结了一些问题:ImportError:cannot import name ENUM_P_TYPE 解决方法为:将/usr/local/lib/python2 ...