poj 1789 Truck History (克鲁斯卡尔)

《UE4游戏开发》之 《查cook资源失败,问题记录》 当项目打包时,cook出错,但是从原始引擎提供的信息中,没有提示具体的那个资源出错,要查到出错资源,还是非常麻烦。 下面就材质cook出错,增加一些日志,方便查找问题做简单记录 材质cook的一个阶段,是收集MaterialShaderMap,如果在这个阶段收集的信息出错,将会在FShaderMapContent::GetOutdatedTypes函数中,因为Shaders指针指向的内存有问题而出错,通过断点发现,FShaderMapContent这个类对象指针为null,而这个类对象的来源于AllMat. 阅读详情


Truck History
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 20140 Accepted: 7791

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.

题目链接:http://poj.org/problem?id=1789


题目大意:长度相同的n个字符数组代表n个点,两个字符数组之间不同字符个数即为这两点之间的距离大小。克鲁斯卡尔算法实现即可。


代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char s[2002][10];
int fa[2002];
struct A
{
    int x,y;
    int len;
}a[2000002];
int cmp(A a,A b)
{
    return a.len<b.len;
}
void get_fa()
{
    for(int i=0;i<2002;i++)
        fa[i]=i;
}
int find(int x)
{
    return x==fa[x]?x:fa[x]=find(fa[x]);
}
void Union(int a,int b)
{
    int a1=find(a);
    int b1=find(b);
    if(a1!=b1)
        fa[a1]=b1;
}
int main()
{
    int n,i,j,k;
    while(scanf("%d",&n)!=EOF&&n)
    {
		getchar();
        int t=0,ans=0,m=0;
        get_fa();
        memset(a,0,sizeof(a));
        for(i=0;i<n;i++)
            scanf("%s",s[i]);
        int l=strlen(s[0]);
        for(i=0;i<n;i++)   //建图过程
        {
            for(j=i+1;j<n;j++)
            {
                int cnt=0;
                for(k=0;k<l;k++)
                {
                    if(s[i][k]!=s[j][k])
                        cnt++;
                }
                a[m].x=i;
                a[m].y=j;
                a[m++].len=cnt;
            }
        }
        sort(a,a+m,cmp);
        for(i=0;i<m;i++)
        {
            if(find(a[i].x)!=find(a[i].y))
            {
                Union(a[i].x,a[i].y);
                ans+=a[i].len;
                t++;
            }
            if(t>n)
                break;
        }
        printf("The highest possible quality is 1/%d.\n", ans);
    }
    return 0;
}


IEPE传感器4mA恒流源接口电路 另外传感器的偏置电压大概在10V多点,一般接个电容把直流分量去掉。这里我们要把恒流源的电流设置在4毫安左右,R1取33Ω差不多正好。经过CR的隔直流电路后的波形是这样的。 阅读详情

相关推荐

使用单调栈求解最大矩形面积问题的C++实现

通过本文的介绍,我们详细讲解了如何使用单调栈求解砖墙中最大矩形面积的问题,并提供了完整的C++代码实现。希望通过本文的学习,你能掌握单调栈的基本概念及其在实际问题中的应用。如果你有任何疑问或建议,欢迎在评论区留言交流。

m0_57781768的博客 818

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

1.题目引入: 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 se

weixin_52914088的博客 406

如何加快香山处理器Chisel->Verilog编译速度

相比使用默认的scala firrtl complier,使用CIRCT能够将香山代码编译到Verilog的速度提高50%左右。在执行make命令时加上MFC=1,例如make verilog MFC=1或make emu MFC=1。在本地从源码编译CIRCT,在编译完成后将circt/bin路径加入PATH中。使用GraalVM免费版作为JVM编译香山比OpenJDK快10%-20%。我们推荐使用GraalVM代替OpenJDK。使用CIRCT编译香山。

专业技术人员的归宿 871

POJ 1789 Kruskal

Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 22819 Accepted: 8849 DescriptionAdvanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vege

仰望天空 422

Ren’py教程《从入门到精通》

Ren’py是什么?Ren'py是一款用于制作视觉小说、冒险游戏、galgame的游戏制作工具,被来自世界各地的数千名创作者使用。Ren'py的名字由Ren’ai和Python混合而成,而Python也是Ren'py所使用的环境语言。Ren'py可以帮助你使用文字、图像和声音来讲述在计算机和移动设备上运行的交互式故事。这些既可以是视觉小说,也可以是生活模拟游戏。易于学习的脚本语言允许 任何人都可以有效地编写大型视觉小说,而它的Python 脚本足以应对复杂的 模拟游戏。

2302_77140651的博客 1万+

华中科技大学 计算机组成原理 educoder Logisim平台 计算机数据表示实验

本文主要是对 计算机数据表示实验的笔记和相关Logisim平台的图,供大家学习交流使用。 需要源文件或者源代码,可以留言评论! 目录实验目的第1关:汉字国标码转区位码实验第2关:汉字机内码获取实验第3关:偶校验编码设计第4关:偶校验解码电路设计第5关:16位海明编码电路设计第6关:16位海明解码电路设计第7关:海明编码流水传输实验第8关:16位CRC并行编解码电路设计第9关:CRC编码流水传输实验实验结果: 实验目的 本实训将帮助同学们巩固对计算机中数据表示方法的理解,要求能设计汉字国标码与区位码之间的转换

weixin_48383580的博客 2万+

poj1789

Truck History Time Limit:2000MS Memory Limit:65536K Total Submissions:8270 Accepted:2970 Description Advanced Cargo Movement, Ltd. uses trucks of different types. S...

weixin_33912453的博客 303

第三方 API 调用 OpenClaw 出现 LLM request timed out 的解决方案

本文主要介绍了第三方 API 调用 OpenClaw 出现 LLM request timed out 的解决方案,希望能对使用OpenClaw的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 8万+

POJ 1789 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 tru

dreambyday 761

微信小程序 - 实现Java微信支付退款功能以及退款流程,微信小程序前端+java后端完整示例源码,微信小程序退款功能详解,小程序订单申请退款和退款回调方法、查询退款等(新版微信支付,详细示例代码)

微信小程序开发-微信支付退款功能以及退款回调方法,微信支付退款API详解,微信小程序支付V3(支付、退款)Java实现微信小程序开发 小程序支付开发-小程序退款功能,微信小程序小程序和公众号 退款功能教程(含申请退款和退款回调,退款回调地址在商户后台配置或者代码自定义)最新版微信小程序支付,退款问题,小程序支付和退款功能详解,小程序申请退款,小程序处理退款,微信小程序支付与退款java,微信小程序退款及回调,JAVA实现微信小程序支付退款功能,退款api调用报错,如何解决退款申请无响应,如何用实现小程序订单

🏆 前端领域优质创作者 4169

C++笔记之emplace_back(),push_back()性能比较i++ 、 ++i

操作是否需要临时对象/拷贝性能需要(构造临时对象)较慢不需要(直接构造)较快i++需要(保存旧值)对于内置类型无影响,但对于自定义类型(如迭代器、大对象)会有拷贝开销++i不需要相对更快(尤其是自定义类型)都存在"是否需要额外的临时对象/拷贝"这一性能差异点和++i都是更高效的版本(避免临时对象/拷贝)和i++都可能产生额外的临时对象(前者构造临时对象,后者保存旧值)对于内置类型(如int),i++和++i性能几乎没有差异(编译器会优化);但对于自定义类型(尤其是迭代器等重量级对象),

小勇博客 106

I - 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...

titi2018815的博客 292

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Truck History 【POJ--1789】【普里姆&&克鲁斯卡尔】【邻接矩阵】

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 ea

zhang_di233的专栏 374

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

老版QQ原生表情gif动态

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

poj 1789 Truck History

首先吐一下槽这是英语阅读训练啊、、、玛德,看不懂啊、、受不了啊,英语太水了啊、、呜呜呜呜#include #include #include #include #include #include using namespace std; struct Edge { int u, v, w; } edge[4000100]; char s[3100][10]; bool c

I am a slow walker, but I never walk backwards! 2825

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

POJ1789-Truck History .

题目链接:http://poj.org/problem?id=1789 题目的大概意思就是给你n个字符串。每个字符串只有7的长度。然后分别给这些字符串编号。不同编号之间的距离就是他们有多少个不同的字母。(同一个位置字母不相同也算)然后一个编号只能由另一个派生出来。派生的代价就是他们呢之间的距离。现在要你求最小的总代价。 编号的范围是2-2000.属于稠密图。求最小生成树最好用prim算法。用克鲁

NaCl__的博客 678

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

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

csyifanZhang的博客 337

Truck History 并查集 POJ 1789

#include &lt;iostream&gt; #include &lt;cstdio&gt; #include &lt;cstring&gt; #include &lt;cmath&gt; #include&lt;algorithm&gt; using namespace std; int fa[2005]; char s[2020][10]; struct Edge{ int ...

dujuancao11的博客 291

POJ 1789 Truck History 最小生成树 kruskal && Prim

Truck History 克鲁斯卡尔 最小生成树,两两不同个数为权值, 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

jianjun的专栏 490

POJ1789 Truck History 最小生成树 + 路径压缩

  首先要强调一点 这不是一道ACM题,这是他妹的一道英语阅读理解。   题意:输入N 代表有N种汽车。每两种汽车之间有一条边,边的权值的定义为 两串字符串之间有几个不同的字母。。。稠密图。。。。普利姆 或者 克鲁斯卡尔 + 路径压缩   我认为后者能通吃所以很无耻的不会第一种。。。。。    1 #include <iostream> 2 #incl...

155

Poj 1789 Truck History【最小生成树】

Truck HistoryTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 21660 Accepted: 8419DescriptionAdvanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable

希望的专栏 808

poj-1789-Truck History

题意: 先给你一个N,然后给你N组字符串。 两个字符串之间的距离就是两个字符串之间不同字符的个数。 让你链接所有的字符串的最小距离。 做法: 把每一个字符串当成一个节点,两个节点之间的权值即为距离。然后求链接所有节点的最小生成树。 据说用prim算法求稠密图,可是我用的是克鲁斯卡尔。。。嘿嘿】 不过得优化一下才能过,不然会超时的。 #include #include #incl

青竹梦 575

poj1789 Truck History

Truck History Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 21523   Accepted: 8372 Description Advanced Cargo Movement, Ltd. uses trucks of different types

张小象 576

POJ1789 ZOJ2158 Truck History【Kruskal算法+并查集】

Truck HistoryTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 32258 Accepted: 12562DescriptionAdvanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable ...

海岛Blog 704
上一篇: noj 1860 保研(01背包 概率dp)
下一篇: codeforces 538 A.Cutting Banner
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址