加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 如何检查一个矢量是否是另一个矢量的子集?

发布时间:2020-12-16 06:03:53 所属栏目:百科 来源:网络整理
导读:目前,我认为我最好的选择是使用std :: set_intersection,然后检查较小输入的大小是否与set_intersection填充的元素数量相同. 有更好的解决方案吗? 解决方法 尝试这个: if (std::includes(set_one.begin(),set_one.end(),set_two.begin(),set_two.end())){/
目前,我认为我最好的选择是使用std :: set_intersection,然后检查较小输入的大小是否与set_intersection填充的元素数量相同.

有更好的解决方案吗?

解决方法

尝试这个:
if (std::includes(set_one.begin(),set_one.end(),set_two.begin(),set_two.end()))
{
// ...
}

约includes().

The includes() algorithm compares two
sorted sequences and returns true if
every element in the range [start2,
finish2) is contained in the range
[start1,finish1). It returns false
otherwise. includes() assumes that the
sequences are sorted using
operator<(),or using the predicate
comp.

跑进来

At most ((finish1 – start1) + (finish2
– start2)) * 2 – 1 comparisons are performed.

Plus O(nlog(n))用于排序向量.你不会比它快得多.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读