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 ...
随机推荐
- input:file样式怎样修改
问题描述: 我需要点击input:file来修改img中的图片,但是input:file样式太丑 解决办法: 给file设置透明度为0,让用户看不见他 创建新的button按钮 修改button按钮样 ...
- 2019 SDN上机第三次作业
2019 SDN上机第三次作业 实验一 利用Mininet仿真平台构建如下图所示的网络拓扑,配置主机h1和h2的IP地址(h1:10.0.0.1,h2:10.0.0.2),测试两台主机之间的网络连通性 ...
- nodejs 连接MySQL后,输出数据带有RowDataPacket、中括号大括号怎么去掉?
var mysql = require('mysql'); var connection = mysql.createConnection({ host : 'localhost', user : ' ...
- xLua 学习
xLua https://github.com/Tencent/xLua 文档 https://tencent.github.io/xLua/public/v1/guide/index.html FA ...
- 第04组 Alpha冲刺(1/4)
队名:斗地组 组长博客:地址 作业博客:Alpha冲刺(1/4) 各组员情况 林涛(组长) 过去两天完成了哪些任务: 1.安排好各个组员的任务 2.收集各个组员的进度 3.写页面 4.写博客 展示Gi ...
- ES6中有关数组的一些新操作
1.Array.isArray() 用于确定传递的值是否是一个 Array. Array.isArray([1, 2, 3]); // true Array.isArray({foo: 123}); ...
- win10挂载efi分区
以管理员权限运行CMD然后输入:diskpart,启动diskpart工具,在diskpart的提示符下依次输入 * list disk-------------------------列出系统中拥有 ...
- ROS机器人路径规划介绍--全局规划
ROS机器人路径规划算法主要包括2个部分:1)全局路径规划算法:2)局部路径规划算法: 一.全局路径规划 global planner ROS 的navigation官方功能包提供了三种全局路径规划器 ...
- css样式重置 移动端适配
css 默认样式重置 @charset "utf-8"; *{margin:0;padding:0;} img {border:none; display:block;} em, ...
- Docker 指定数据储存目录
Docker 指定储存目录(原参数 --graph 已经失效 .) 方法一 一.在 Docker 配置文件中配置 /etc/docker/daemon.json 下面的命令是在 daemon.json ...