CCF-CSP认证 2024年3月 2.相似度计算

这里用一下 set_intersaction()函数来计算交集

set_intersection()作用是求两个集合的交集:

其中有5个参数:firts1,last1,first2,last2,result。
他们都是迭代器。需要注意的是,所求的两个集合必须是有序的,不然运行时会出现错误。
例子

set_intersection(nums1.begin(), nums1.end(), nums2.begin(),nums2.end(),inserter(re,re.begin()));

这里要注意加inserter可能是新加的C++特性,最后一个参数写re.begin会报错。

set_union同理。

并且使用字符串hash加快处理速度

#pragma GCC optimize(2, 3, "Ofast", "inline")
#include 
using namespace std;
set a;
set b;
unsigned int BKDRHash(string str)
{
    unsigned int seed = 131; // 31 131 1313 13131 131313等质数
    unsigned int hash = 0;
    for(int i=0;i

你可能感兴趣的:(哈希算法,算法)