1063 Set Similarity (25分)

本文介绍了一种计算两个集合相似度的方法,分子为两集合中相同元素的数量(去重),分母为两集合总元素数量(去重)。通过C++代码实现,使用unordered_set存储集合元素,遍历集合进行比较计算。

Given two sets of integers, the similarity of the sets is defined to be N​c​​/N​t​​×100%, where N​c​​ is the number of distinct common numbers shared by the two sets, and N​t​​ is the total number of distinct numbers in the two sets. Your job is to calculate the similarity of any given pair of sets.

Input Specification:

Each input file contains one test case. Each case first gives a positive integer N (≤50) which is the total number of sets. Then N lines follow, each gives a set with a positive M (≤10​4​​) and followed by M integers in the range [0,10​9​​]. After the input of sets, a positive integer K (≤2000) is given, followed by K lines of queries. Each query gives a pair of set numbers (the sets are numbered from 1 to N). All the numbers in a line are separated by a space.

Output Specification:

For each query, print in one line the similarity of the sets, in the percentage form accurate up to 1 decimal place.

Sample Input:

3
3 99 87 101
4 87 101 5 87
7 99 101 18 5 135 18 99
2
1 2
1 3

Sample Output:

50.0%
33.3%

题意:求两个集合相似度,分子为相同的元素个数(去重),分母为总共的元素个数(去重)

#include<unordered_set>
#include<iostream>
#include<vector>

using namespace std;

int main(){

    int n;
    cin >> n;
    vector<unordered_set<int> > vec (n + 1);
    for(int i = 1; i <= n; i++){
        int m;
        scanf("%d", &m);
        for(int j = 0; j < m; j++){
            int temp;
            scanf("%d", &temp);
            vec[i].insert(temp);

        }


    }
    int k;
    cin >> k;
    for(int i = 0; i < k; i++){

        int a, b;
        scanf("%d %d", &a, &b);
        int nc = 0;
        int nt = 0;
        for(auto it : vec[a]){
    
            if(vec[b].find(it) != vec[b].end()){
                nc++;
            } 
        }
        nt = vec[a].size() + vec[b].size() - nc;
        float result = 1.0 * nc / nt * 100;
        printf("%.1f%%\n", result);
    }
    return 0;
}

 

基于径向基函数神经网络RBFNN的自适应滑模控制学习(Matlab代码实现)内容概要:本文介绍了基于径向基函数神经网络(RBFNN)的自适应滑模控制方法,并提供了相应的Matlab代码实现。该方法结合了RBF神经网络的非线性逼近能力和滑模控制的强鲁棒性,用于解决复杂系统的控制问题,尤其适用于存在不确定性和外部干扰的动态系统。文中详细阐述了控制算法的设计思路、RBFNN的结构与权重更新机制、滑模面的构建以及自适应律的推导过程,并通过Matlab仿真验证了所提方法的有效性和稳定性。此外,文档还列举了大量相关的科研方向和技术应用,涵盖智能优化算法、机器学习、电力系统、路径规划等多个领域,展示了该技术的广泛应用前景。; 适合人群:具备一定自动控制理论基础和Matlab编程能力的研究生、科研人员及工程技术人员,特别是从事智能控制、非线性系统控制及相关领域的研究人员; 使用场景及目标:①学习和掌握RBF神经网络与滑模控制相结合的自适应控制策略设计方法;②应用于电机控制、机器人轨迹跟踪、电力电子系统等存在模型不确定性或外界扰动的实际控制系统中,提升控制精度与鲁棒性; 阅读建议:建议读者结合提供的Matlab代码进行仿真实践,深入理解算法实现细节,同时可参考文中提及的相关技术方向拓展研究思路,注重理论析与仿真验证相结合。
### Halcon 中的相似性匹配功能 在 Halcon 中,相似性匹配是一种用于识别图像中特定模式的技术。该技术通过模板匹配的方式,在目标图像内寻找与给定模型最接近的部。为了实现这一目的,Halcon 提供了一系列算子来创建和应用这些模型。 #### 创建相似性模型 要执行相似性匹配,首先需要定义一个或多个感兴趣区域作为模板,并基于此构建模型。这可以通过 `create_similarity_model` 函数完成: ```cpp // 定义模板窗口并读取模板图像 read_image (Image, 'template_path') reduce_domain (Image, Region, ImageReduced) // 使用默认参数创建相似度量模型 create_similarity_model (ImageReduced, 0.5, 0.7, 'use_polarity', \ 'gauss', 3, 1, SimilarityModelID) ``` 上述代码片段展示了如何加载一幅图片到内存中,并将其指定为模板的一部;随后调用 `create_similarity_model()` 来初始化一个新的相似性检测器实例[^2]。 #### 应用相似性模型进行搜索 一旦建立了模型之后,则可以利用它来进行实际的目标查找工作。下面的例子说明了怎样在一个新输入的画面里定位之前设定好的对象位置: ```cpp // 加载待处理的新图象 read_image (SceneImage, 'scene_path') // 执行相似性匹配操作 find_all_similar_objects (SimilarityModelID, SceneImage, MinScore, MaxOverlap,\ NumMatches, RowBegin, ColumnBegin, Angle, ScaleRow, \ ScaleColumn, Score, HandleArray) ``` 这里的关键在于函数 `find_all_similar_objects()`, 这个命令会遍历整个场景图像去发现所有可能存在的匹配项,并返回它们各自的坐标以及其他相关信息如角度旋转和平移缩放因子等属性值[^3]。 #### 结果可视化 最后一步通常是将找到的结果直观地显示出来以便验证效果好坏与否: ```cpp dev_display(SceneImage); for i := 0 to |HandleArray|-1 by 1 do dev_set_color ('red'); gen_rectangle1 (RowBegin[i], ColumnBegin[i],\ RowBegin[i]+ScaleRow[i]*TemplateHeight,\ ColumnBegin[i]+ScaleColumn[i]*TemplateWidth); endfor; ``` 这段脚本会在原始画面上绘制红色矩形框标记出每一个被成功辨认出来的物体轮廓边界线[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值