Truck History(最小生成树)

Truck History(建图+最小生成树) Truck History(建图+最小生成树) 先摆题 题目巨难读,可能是我英语太菜了吧。。 大意是这样的,给你n个七位字符串,两个字符串的距离就是不同的字母个数,字符串可以变形,每次改变一个字符,问如何能够用最少的操作让一个字符串挨个变成其他字符串的样子。答案输出1/操作次数。 多个输入,0截止。 题目一看,整活最小生成树,那么问题来了,怎么生成? 最小生成树有两种做法,一种是加边法()Kru... 阅读详情
Problem Description
Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other for furniture, or for bricks. The company has its own code describing each type of a truck. The code is simply a string of exactly seven lowercase letters (each letter on each position has a very special meaning but that is unimportant for this task). At the beginning of company's history, just a single truck type was used but later other types were derived from it, then from the new types another types were derived, and so on.

Today, ACM is rich enough to pay historians to study its history. One thing historians tried to find out is so called derivation plan -- i.e. how the truck types were derived. They defined the distance of truck types as the number of positions with different letters in truck type codes. They also assumed that each truck type was derived from exactly one other truck type (except for the first truck type which was not derived from any other type). The quality of a derivation plan was then defined as
1/Σ(to,td)d(to,td)

where the sum goes over all pairs of types in the derivation plan such that to is the original type and td the type derived from it and d(to,td) is the distance of the types.
Since historians failed, you are to write a program to help them. Given the codes of truck types, your program should find the highest possible quality of a derivation plan.
 

Input
The input consists of several test cases. Each test case begins with a line containing the number of truck types, N, 2 <= N <= 2 000. Each of the following N lines of input contains one truck type code (a string of seven lowercase letters). You may assume that the codes uniquely describe the trucks, i.e., no two of these N lines are the same. The input is terminated with zero at the place of number of truck types.
 

Output
For each test case, your program should output the text "The highest possible quality is 1/Q.", where 1/Q is the quality of the best derivation plan.
 

Sample Input
4 aaaaaaa baaaaaa abaaaaa aabaaaa 0
 
Sample Output
The highest possible quality is 1/3

题意:
有n个字符串,每一个字符串都是7个字母,字符串之间的距离是 他们字母不同的个数,然后求串通他们的最小的距离。
看出是最小生成树就好了,直接套用模板。


#if 0
#include<iostream>
#include<cstring>
using namespace std;
int mapp[3000][3000];
int minn[3000],n;
bool u[3000];

void prime()
{
	
	minn[1]=0;
                       
	for(int i=1; i<=n; i++)           // 
	{
		int k=0;
		for(int j=1; j<=n; j++)             //找出与白点 连接权值最小的蓝点 k  
		{
			if(!u[j]&&minn[k]>minn[j])
			{
				k=j;
			}
		}
		u[k]=1;           //k 蓝点 
		
		for(int j=1; j<=n; j++)
		{
			if(!u[j]&&mapp[k][j]<minn[j])
				minn[j]=mapp[k][j];	
		} 
	} 
}

int main()
{
	while(cin>>n&&n)
	{
		string s[3000];
		memset(mapp,0,sizeof(mapp));
		memset(minn,0x7f,sizeof(minn));
		memset(u,0,sizeof(u));
		for(int i=1; i<=n; i++)
		{
			cin>>s[i];	
		}	
	
		for(int i=1; i<=n; i++)
		{
			for(int j=1; j<=n; j++)
			{
				int x=0;
				for(int k=0; k<7; k++)
				{
					if(s[i][k]!=s[j][k])
						x++;
				}
				mapp[i][j]=x;
			}
		}
	
		int sum=0;
		prime();
		for(int i=1; i<=n; i++)
		{
			sum+=minn[i];
		}
		cout<<"The highest possible quality is 1/"<<sum<<"."<<endl;		
    }	                      

}
#endif





















POJ1789-Truck History【Prim】 北大POJ1789-Truck History【Prim】 解题报告+AC代码 立即下载

相关推荐

Truck History ( 卡车历史)

Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other for furniture, or for bricks. The company has its own code describing each type of a t...

shiuxin的博客 1000

Windowns下Git环境配置-命令行方式

文章目录一、配置Git1.1 下载Git并安装1.2 配置本地Git用户名和邮箱1.3 注册GitHub二、生成本地公钥,放到GitHub上-SSH Key2.1 生成本地公钥命令2.2 查看生成的公钥2.3 在GitHub放上公钥并测试连通性三、创建项目实操四、可能出现的问题4.1.push不成功4.2.提示SSL的问题4.3.域名不能解析的问题4.4.如果github连接不上的问题 一、配置Git 1.1 下载Git并安装 Git官网 默认安装,根据需要修改安装路径 1.2 配置本地Git用户名和邮箱

学习工作笔记 1135

Truck History(最小生成树prim算法)

Truck History(最小生成树prim算法)

Charlotte_1236的博客 426

《Hadoop大数据技术原理与应用》(第2版)黑马程序员的课后习题答案

《Hadoop大数据技术原理与应用》(第2版)黑马程序员的课后习题答案

qq_36773158的博客 4646

手把手教你设计反激开关电源:从整流滤波到PCB布局的实战避坑指南

本文是一份反激开关电源的实战设计指南,重点解析了从整流滤波电路到PCB布局的关键细节与常见陷阱。文章深入探讨了输入保护元件协同设计、EMI滤波器优化、整流桥与滤波电容选型,并详细阐述了如何通过优化PCB布局来确保安规、最小化功率回路面积以控制噪声,旨在帮助工程师和爱好者规避设计误区,提升电源的可靠性与性能。

yhn45678901的博客 692

Truck History(POJ1789)

//感受,刚开始自己给a[ ]数组少打了一个0,搞得我一直Runtime Error!,,要小心啊。 #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; char c[2100][10

jiangjiashi的博客 574

[原创]Linux 802.11n CSI tool Monitor模式

Linux 802.11n CSI tool Monitor模式 使用AP模式的缺陷在于ping 命令速度比较慢,且不能精确控制发送的参数,比如接收的包数量是不可控的。Monitor模式可以调制发送速率、发包数量、发送天线个数、HT模式、short/long guard interval等等,因此调通Monitor模式是必须的。期间参考了博主沃一德的CSI Tool安装使用讲解,对他的工作表示感...

u014645508的博客 1万+

Truck History (最小生成树)

    Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other for furniture, or for bricks. The company has its own code describing each type of...

Z2Min_ 559

NSGA-III相关笔记

NSGA-III目录目的区别NSGA-III的算法流程非支配排序详解归一化详解 目录 NSGA-III基于matlab的实现 参考文献 1.An Evolutionary Many-Objective Optimization Algorithm Using Reference-point Based Non-dominated Sorting Approach,Part I: Solving P...

weixin_42555400的博客 1万+

SAP FI 会计科目表(COA)可直接套用配置模板

摘要:本文提供了SAP S/4HANA环境下可直接套用的会计科目表(COA)配置模板,包含科目编码规则、号段规划、科目组设置等核心内容。模板采用10位数字编码,按资产(1000)、负债(2000)、权益(3000)、成本(4000)、收入(5000)、费用(6000)六大类划分号段,并预设科目组控制字段状态。适用于集团/单一公司、国内/跨国企业场景,支持多表架构映射,配置完成后可通过事务码SAKO验证科目清单。模板遵循"前4位固定一级科目"原则,企业可根据行业特性调整明细科目。

金牌架构师 267

(最小生成树)POJ1789Truck History

POJ1789Truck History 题意&思路: 给你n个长度为7的字符串,每两个字符串之间的权值为相同位置字符不同的个数。每个字符串都由另一个字符串变化而来,变化的质量为1/权值和。求最大质量。 其实就是求最小权值和。 模板题。 代码: #include<iostream> #include<stdio.h> #include<stdlib.h>...

Z7784562的博客 218

DeepSeek-R1 论文阅读 DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning

和。这些模型的核心创新点是通过强化学习(Reinforcement Learning, RL)来提升大型语言模型(LLM)的推理能力,而没有依赖传统的监督微调(Supervised Fine-Tuning, SFT)作为预训练的步骤。是一种通过大规模强化学习直接训练的模型。它在推理能力上表现出色,能够自然地展现出许多强大且有趣的推理行为。但它也有一些问题,比如可读性差和语言混合。这意味着模型在生成文本时,有时会显得不太清晰,或者不一致地使用不同语言。为了解决这些问题并进一步提升推理能力,研究者提出了。

CSPhD-winston的博客 1839

POJ 1789 Truck History(最小生成树)

POJ 1789 Truck History(最小生成树) http://poj.org/problem?id=1789 题意:        用一个7位的string代表一个编号,两个编号之间的distance代表这两个编号之间不同字母的个数。一个编号只能由另一个编号“衍生”出来,代价是这两个编号之间相应的distance,现在要找出一个“衍生”方案,使得总代价最小,也就是distance

code 976

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Truck History最小生成树

Truck History 原题链接https://vjudge.net/contest/352170#problem/E 题意为有 n行字母 他们之间的距离就是不同字母的个数,相当于题目将所有的地点给出,我们只需要枚举写出地图,正常计算即可。 注意Kruskal很容易记忆化超限, Prim: #include <algorithm> #include <cmath> ...

yeyuluo的博客 270

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Truck History——最小生成树

Truck History Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description Advanced Cargo Movement, Ltd. uses trucks of different types. Som

空白页 529

poj1789 Truck History (最小生成树)

点击打开链接 历史上,曾用7个小写字母来表示每种truck的型号,每两种型号之间的差距为字母串中不同字母的个数。现在给出n种不同型号的truck,问怎样使 1/Σ(to,td)d(to,td)的值最小。(即找到一条连接所有truck的最短路径。典型的最小生成树的问题, discuss里说,Prim算法适合稠密图,Kruskal算法适合稀疏图,可以使用prim和kruskal两种方法。该题是稠

hello_fei 1110

POJ 1789Truck History——————最小生成树

Truck History Language:DefaultTruck History Time Limit: 2000MSMemory Limit: 65536KTotal Submissions: 33305Accepted: 12935DescriptionAdvanced Cargo Movement, Ltd. uses trucks of different types. Some...

鸿杰 的博客 252

Truck History(最小生成树)

题目: Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other for furniture, or for bricks. The company has its own code describing each type of...

stdio_xuege的博客 366

最小生成树专题 F - Truck History(prime模板算法)

题意 : 什么鬼的汽车公司有个惊人的发现,吧啦吧啦吧啦…………….然后就给你n个卡车的车牌(我就没见过这种车牌),每2辆车的车牌中,有多少个字母不同就代表着这两辆车经历的多少年的演变。然后就让你求所有的这些车至少经历了多少年的演变。 这道题类似于坐标构图,数据量有些大 ,然后就: 。。。不好意思贴错了,是这个: 妈耶,疯狂优化以后终于AC了。。。。 最后发现是被string类型的...

大梦小半 261

Truck History 最小生成树

Truck History Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Description Advanced Cargo Movement, Ltd. uses trucks of different types. Some

热爱编程,热爱技术 564

poj1789 Truck History 最小生成树

题意: 用一个7为的字符串代表一个卡车的编号,每两个字符串的差异值为它们不同的字母的位数。如: abaaaaa aabaaaa 的差异值为2,因为他们有两位不同。 每个卡车的编号可以由其他编号变换过来,代价为它们的差异值。 为要生成所有的编号,最小的代价为多少。 思路: 本题可以转化成最小生成树。 每个节点代表一个编号,与其他所有节点连边,权值为代价。 可见,最小

Shion的专栏 705

POJ 1789 Truck History 最小生成树

DescriptionAdvanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other for furniture, or for bricks. The company has its own code describing each ty

Merry_hj的博客 366

POJ 1789 Truck History【题解报告|最小生成树】

题目大意 用一个7位的string代表一个编号,两个编号之间的distance代表这两个编号之间不同字母的个数。一个编号只能由另一个编号“衍生”出来,代价是这两个编号之间相应的distance,现在要找出一个“衍生”方案,使得总代价最小,也就是distance之和最小。 例如有如下4个编号: aaaaaaa baaaaaa abaaaaa aabaaaa 显然的,第二,第三和第四编号分别从第一编号衍生出来的代价最小,因为第二,第三和第四编号分别与第一编号只有一个字母是不同的,相应的distance都是1

csyifanZhang的博客 336

POJ1789 Truck History 最小生成树

题目大意:ACM公司给自己的运输车编号,每辆车的编号都是互不相同的7个小写字母,定义每两辆车之间的距离为:这两辆车编号上相同位置不同字母的个数,现在让你找出n辆车之间距离和的最小值。 分析:典型的最小生成树问题,把n辆车以及之间的距离看做一个无向图,先找出图中各边的权值(一个循环就行),然后就是裸的Prime了。 实现代码如下: #include #include

AC_Gibson的专栏 521
上一篇: Wormholes(负权回路)
下一篇: 8.9训练总结
Joined
博客等级 码龄10年 19粉丝 134原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值