Set Similarity
问题 A: Set Similarity (25)
时间限制: 1 Sec 内存限制: 32 MB
提交: 292 解决: 126
[提交][状态][讨论版][命题人:外部导入]
题目描述
Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*100%, where Nc is the number of distinct common numbers shared by the two sets, and Nt is the total number of distinct numbers in the two sets. Your job is to calculate the similarity of any given pair of sets.
输入
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 (<=104) and followed by M integers in the range [0, 109]. 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.
输出
For each query, print in one line the similarity of the sets, in the percentage form accurate up to 1 decimal place.
样例输入
3
3 99 87 101
4 87 101 5 87
7 99 101 18 5 135 18 99
2
1 2
1 3
样例输出
50.0%
33.3%
自己代码:
#include<iostream>
#include<set>
using namespace std;
int main() {int N,num,element;int search[2];double shuchu[2000];set<int> input[50];while (scanf("%d", &N) != EOF) {//共有N组set输入int jishu = 0;for (int i = 0; i < N; i++){scanf("%d", &num);//每组set有几个数for (int j = 0; j < num; j++) {scanf("%d", &element);input[i].insert(element);}}//输入要查询的set组数scanf("%d", &num);for (int i = 0; i < num; i++) {scanf("%d %d", &search[0], &search[1]);//查找相同的个数int Nc = input[search[0] - 1].size() + input[search[1] - 1].size();set<int> merge;//取出要查询的两个set的合并for (set<int>::iterator it = input[search[0] - 1].begin(); it != input[search[0] - 1].end();it++) {merge.insert(*it);}for (set<int>::iterator it = input[search[1] - 1].begin(); it != input[search[1] - 1].end();it++) {merge.insert(*it);}int Nt = merge.size();Nc = Nc - Nt;double result = (double)Nc / (double)Nt * 100;shuchu[jishu++] = result;}for (int i = 0; i < jishu; i++)printf("%.1f%%\n", shuchu[i]);}system("pause");return 0;
}
注意:本题练习的是set容器的用法,set的主要用途是自动去重并按升序排序,若需要处理不唯一的情况,则需要使用multiset,另外还增加了unordered_set,以散列代替内部红黑树。要读懂题意。
Set Similarity相关推荐
- 1063 Set Similarity
1. 这题需要利用set容器的去重功能,因此使用set来存放每一组的数据. 2. 起初我的计算相似度的函数是这样设计的:传入set1和set2,声明一个set3,将set1中的数据全部插入set3中, ...
- R语言计算杰卡德相似系数(Jaccard Similarity)实战:自定义函数计算Jaccard相似度、对字符串向量计算Jaccard相似度、将Jaccard相似度转化为Jaccard距离
R语言计算杰卡德相似系数(Jaccard Similarity)实战:自定义函数计算Jaccard相似度.对字符串向量计算Jaccard相似度.将Jaccard相似度转化为Jaccard距离 目录 R ...
- LDNFSGB: prediction of long non-coding rna and disease association using network feature similarity
LDNFSGB: prediction of long non-coding rna and disease association using network feature similarity ...
- ReSimNet: drug response similarity prediction using Siamese neural networks
ReSimNet:使用Siamese神经网络进行药物反应相似性预测 Abstract Motivation: Traditional drug discovery approaches identif ...
- 使用Keras计算余弦相似度(Cosine Similarity)
因为Merge函数在Keras新版本中已经不再使用了,在计算批次余弦相似度时,需要自定义函数.余弦相似度定义如下: 要计算两个向量相似度有如下步骤: 分别计算两个向量l2范式,计算两个向量的点乘 点乘 ...
- 【 Notes 】MOBILE LOCALIZATON METHOD BASED ON MULTIDIMENSIONAL SIMILARITY ANALYSIS
目录 ABSTRACT INTRODUCTION LINEAR TOA LOCALIZATION MULTIDIMENSIONAL SIMILARITY ANALYSIS SUBSPACE BASED ...
- 自定义评分器Similarity,提高搜索体验
首先说一下lucene对文档的评分规则: score(q,d) = coord(q,d) · queryNorm(q) · ∑ (tf(t in d) · idf(t)2 · t.get ...
- 全网独发gensim中similarities.Similarity用法
index = similarities.MatrixSimilarity(lsi[corpus]) # 管网的原文翻译如下: 警告:similarities.MatrixSimilarity类仅仅适 ...
- 1063. Set Similarity (25)
题目例如以下: Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*100%, where Nc ...
- Bit-Scalable Deep Hashing with Regularized Similarity Learning for Image Retrieval and Person Re-ide
总结:(1)对基于三元组学习的损失函数利用拉普拉斯矩阵增加了规则化项 (2)通过给hashing code 的每一Bit 给定一个权重,从而实现Bit-Scalable (3)设计tanh-like ...
最新文章
- Yii2掉index.php?r=
- 25条实用的Python一行代码,你用过哪些?
- Rsync+inotify搭建使用
- Java之HashMap.values()转List时的错误和正确操作
- 从零学ELK系列(四):Docker安装Elasticsearch(超详细图文教程)
- Halcon 抓圆工具spoke
- python求解矩阵搜索问题,矩阵中每一行和第一列都是递增的 给定一个元素查找矩阵中是否存在该元素
- 简析Windows Linux的内核映射
- Ubuntu20安装gcc6.3.0
- matlab各种文件类型,MATLAB中的文件类型总结
- 977计算机考研,中国海洋大学 977计算机技术与软件工程专业课经验分享
- 51单片机入门——蜂鸣器
- signature=a5d52dd3b1c2e95cc6ca952d8f8e8a05,6d53beb98227311df5d5a4ccf0177f23
- 2022年N1叉车司机考试题库及N1叉车司机证考试
- iOS-使用CoreLocation定位
- Uaexpert操作手册
- 双球坐标系_2.1 天球坐标系和地球坐标系
- mysql建图书馆表_创建学校图书馆数据库 BookDB
- Nginx和Tomcat优化
- office卸载后无法重装终极解决办法