Truck History POJ - 1789
题目链接: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的更多相关文章
- (最小生成树)Truck History --POJ -- 1789
链接: http://poj.org/problem?id=1789 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 2213 ...
- Truck History - poj 1789 (Prim 算法)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20884 Accepted: 8075 Description Ad ...
- F - Truck History - poj 1789
有一个汽车公司有很多年的汽车制造历史,所以他们会有很多的车型,现在有一些历史学者来研究他们的历史,发现他们的汽车编号很有意思都是有7个小写字母组成的,而且这些小写字母具有一些特别的意义,比如说一个汽车 ...
- Truck History POJ - 1789 板子题
#include<iostream> #include<cstring> #include<algorithm> #include<stdio.h> u ...
- poj 1789 prime
链接:Truck History - POJ 1789 - Virtual Judge https://vjudge.net/problem/POJ-1789 题意:先给出一个n,代表接下来字符串的 ...
- poj 1789 Truck History
题目连接 http://poj.org/problem?id=1789 Truck History Description Advanced Cargo Movement, Ltd. uses tru ...
- POJ 1789 Truck History【最小生成树简单应用】
链接: http://poj.org/problem?id=1789 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- Kuskal/Prim POJ 1789 Truck History
题目传送门 题意:给出n个长度为7的字符串,一个字符串到另一个的距离为不同的字符数,问所有连通的最小代价是多少 分析:Kuskal/Prim: 先用并查集做,简单好写,然而效率并不高,稠密图应该用Pr ...
- POJ 1789 -- Truck History(Prim)
POJ 1789 -- Truck History Prim求分母的最小.即求最小生成树 #include<iostream> #include<cstring> #incl ...
随机推荐
- 05justify-content
display: flex; 的默认轴是x轴 justify-content: 设置主轴上的子元素排列的方式 所以在使用之前要确定好哪一个是主轴 /* justify-content:flex-sta ...
- 数据库(update tab1 set tab1.name=tab1.name+(select t2.name from tab2 t2 where t2.id=tab1.id))
有t1 和 t2 两个表,表中的数据和字段如下: 执行 如下SQL语句: update tab1 set tab1.name=tab1.name+(select t2.name from tab2 t ...
- python27期尚哥讲TCP:
TCP:传输控制协议(使用情况多于udp) 稳定:保证数据一定能收到 相对UDP会慢一点 web服务器一般都使用TCP(银行转账,稳定比快要重要)TCP通信模型: 在通信之前,必须先等待建立链接 TC ...
- 浅谈C++ STL deque 容器
浅谈C++ STL deque 容器 本篇随笔简单介绍一下\(C++STL\)中\(deque\)容器的使用方法及常见使用技巧. deque容器的概念 \(deque\)的意义是:双端队列.队列是我们 ...
- layui实现分页
一 准备工作 首先必须先引入layui的完整目录,也就是你下载下来的整个layui的目录都要放在你的资源文件夹下,也就是这个文件目录 刚开始接触layui的时候,以为和jquery,vue等框架一样, ...
- 合并K个有序数组-Java
package com.rao.algorithm; import java.util.Arrays; /** * @author Srao * @className MergeK * @date 2 ...
- 9.27 csp-s模拟测试53 u+v+w
T1 u 拿到题感觉他很水,但到死没想到正解,只会骗部分分(我太弱了) 考虑用两个差分数组维护,不同的是最后更新答案是$a[i][j]+=a[i-1][j-1]$,首先考虑在斜着加的起点,就是竖着的直 ...
- Python源码:字典
一.创建增加修改 1.实现代码 #创建 stu_info = { "xiedi":28, "liuhailin":27,"daiqiao": ...
- Uboot启动流程分析(二)
1.前言 在前面的文章Uboot启动流程分析(一)中,链接如下: https://www.cnblogs.com/Cqlismy/p/12000889.html 已经简单地分析了low_level_i ...
- vue自定义事件---拖拽
margin布局拖拽 Vue.directive('drag', { bind(el, binding, vnode, oldVnode) { const dialogHeaderEl = el.qu ...