联合查找算法的实现

编程入门 行业动态 更新时间:2024-10-14 12:26:22
本文介绍了联合查找算法的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一系列的键值对.每个键有2个值.键的值可能相符. 最初,我从Key1开始,ValueKey1,ValueKey2存储在一个集中.(也许是数组). 现在,对于每个连续的Keyi,我检查Valuei,Valuei + 1是否在集合中.如果其中任何一个在集合中,请加入集合. 否则,如果两个KeyValue都存在于集合中,则丢弃该键. 我如何用C ++实现这个东西,我的想法很少,所以我建议如果可能的话,代码片段或提示会真的很有帮助.

I have a series of Key value pairs. Each Key has 2 values. Values of Keys ma coincide. Initially i start with Key1, ValueKey1, ValueKey2 are stored in a set.(Maybe Array). Now for each consecutive Keyi, i check if Valuei, Valuei+1 are in the set. If any one of them is in the set, then join the set. Else if both KeyValues are present in a set, discard that key . How can i implement this thing using C++, i have very less idea, so i would suggest if possible a code snippet or a hint would be really helpful.

推荐答案

A暗示?好的,我会给您一个提示,但是首先,请看我对问题的评论,并意识到您对问题的表述不清楚. 现在,有一个提示:您只需要实现集合理论操作(例如,union(析取)).只需通过该操作的定义 即可实现. 尝试一下,如果遇到任何问题,请向我们展示您的代码;如果您还解释您的困难所在,我们可能会为您提供帮助.
—SA
A hint? OK, I''ll give a hint, but first, see my comment to the question and realize that your formulation of the problem is not clear. Now, a hint: you simply need implementation of set-theory operation like union (disjunction). Simply implement it by definition of that operation. Try it and show us your code if you face any problems; if you also explain where is your difficulty, we can probably help you.
—SA

更多推荐

联合查找算法的实现

本文发布于:2023-11-30 09:19:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649480.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!