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代码 立即下载

相关推荐

STM32F103VET6实战:用W25Q64外部Flash实现Bootloader+Application双备份(含完整代码解析)

本文详细介绍了基于STM32F103VET6微控制器和W25Q64外部Flash实现Bootloader+Application双备份固件升级的完整方案。通过精心设计的Flash分区策略、可靠的Bootloader程序以及包含双重校验和自动回滚机制的升级流程,有效解决了远程升级过程中断电导致设备变砖的风险,确保了工业嵌入式系统的高可靠性与稳定性。

linux的博客 823

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

App渗透 - 人脸识别登录绕过

一、APP抓包和逆向破解加密算法打开APP是一个登录框抓包后发现参数被加密了使用Jadx脱源码发现,并没有加壳也没有混淆,运气很好根据经验,先搜索Encrypt、Decrypt等关键字,发现在Common.js中有一个encryptData函数定位过去,一套加解密算法都写好了放在这放到浏览器console里面调试,果然没错二、寻找注入点首先测试了一下注入明文:{"userName":"TEST'...

渗透测试研究中心 2823

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

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

Charlotte_1236的博客 426

ESP32接入扣子(Coze) API使用自定义智能体

本示例将使用ESP32开发板通过WiFi接入 **Coze API**,实现一个简单的聊天机器人功能。用户可以通过串口向机器人输入问题,ESP32将通过Coze API与智能体进行通信,并返回对应的回复。本文将详细介绍了如何通过HTTP请求和JSON解析来与API进行交互,并给出完整的代码示例。

宁子希的博客 1万+

金属粘结剂喷射3D打印技术:工艺流程与后处理关键

金属粘结剂喷射(Binder Jetting)是一种创新的增材制造技术,通过逐层喷射粘合剂将金属粉末粘结成型,再经过脱脂和烧结等后处理工序获得最终零件。这项技术的核心优势在于无需支撑结构、可实现批量生产,并且材料利用率高。在3D打印领域,金属BJ技术特别适合中小尺寸、结构复杂且表面质量要求高的零件生产。其工艺流程包括前期数据处理、打印生胚阶段、拆包与清粉,以及关键的渗透、脱脂和烧结后处理环节。后处理工艺的控制直接决定了零件的机械性能和尺寸精度,其中烧结工艺尤为关键,需要精确控制温度曲线和气氛环境。金属BJ打

weixin_35751194的博客 83

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

win11禁止更新,草履虫教程

本文介绍了彻底禁止Windows 11系统更新的组合方法,包括禁用核心服务、修改注册表、关闭计划任务和使用组策略(专业版适用)。作者特别提醒,禁止更新会影响系统安全性,建议实体机保持更新,仅虚拟机等特殊情况下使用这些方法。同时强调即使禁用更新,也应定期手动检查重要安全补丁。文章最后附上了作者的个人网站信息。

testwzc1的博客 560

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

特征拼接(Feature Concatenation)技术全景解析

特征拼接是深度学习中的核心特征融合技术,通过在指定维度连接不同来源的特征张量,创造性地解决了多源、多尺度特征融合的关键挑战。这种简单却强大的操作已成为现代神经网络架构设计的基石。

浩瀚之水的专栏 1640

Sigrity System SI SerialLink模式进行Pcie3协议仿真分析操作指导-pcie3_client_single_pre

Sigrity System SI SerialLink模式提供了10个协议合规性检查工具模板,用户可以将根据实际应用替换模板中的SPICE文件,然后进行协议仿真分析,同时软件还提供了目标结果的模板MASK以及该协议需要检查的项目,通过协议分析视为满足设计要求,下面介绍pcie3_client_single_pre仿真分析,具体操作如下。Random(Rj):随机抖动,该抖动用高斯概率分布来描述,通常是由热噪声和其它随机噪声引起的,默认为1.24%UI RMS(平均值),即和标准值的偏差为1.24%UI。

weixin_54787054的博客 598

(最小生成树)POJ1789Truck History

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

Z7784562的博客 218

SAP-ABAP:字符与数值类型转换详细指南

SAP-ABAP:字符与数值类型转换详细指南

baidu_35680696的博客 1478

POJ 1789 Truck History(最小生成树)

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

code 976

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Truck History最小生成树

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

yeyuluo的博客 270

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

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、付费专栏及课程。

余额充值