1063 Set Similarity (25 分)

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 Nlines 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%

题意:集合相似性=(两个集合的公共数对/两个集合互相不同的总数)*100%

求这个相似性

解析:排序二分查找,发现会有测试点超时,去除重复,用set

#include<bits/stdc++.h>
using namespace std;#define e exp(1)
#define pi acos(-1)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
int gcd(int a,int b) {return b?gcd(b,a%b):a;
}set<int> lis[3000];
int n,k;int main() {int no = 1;scanf("%d",&n);for(int i = 1; i <= n ; i++) {int m,v;scanf("%d",&m);for(int j = 0 ; j<m; j++) {scanf("%d",&v);lis[i].insert(v);}}scanf("%d",&k);for(int i =0 ; i < k ; i++) {int l1,l2,same = 0;scanf("%d%d",&l1,&l2);set <int> ::iterator it;for(it = lis[l1].begin() ; it!=lis[l1].end(); it++) {if(lis[l2].find(*it) != lis[l2].end())same++;}float rate = float(same) / float(lis[l1].size()+lis[l2].size()-same) * 100;printf("%.1f%%\n",rate);}return 0;
}

1063 Set Similarity相关推荐

  1. PAT甲级1063 Set Similarity:[C++题解]哈希表、去重

    文章目录 题目分析 题目链接 题目分析 来源:acwing 分析:集合相似度是两个集合A.B都有的数字个数,除以两者不同的数字个数,有以下公式:集合相似度 =NcNt=A∩BA+B−Nc=\frac{ ...

  2. 1063 Set Similarity

    1. 这题需要利用set容器的去重功能,因此使用set来存放每一组的数据. 2. 起初我的计算相似度的函数是这样设计的:传入set1和set2,声明一个set3,将set1中的数据全部插入set3中, ...

  3. 1063. Set Similarity (25)

    题目例如以下: Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*100%, where Nc ...

  4. 【最后测试点超时】1063 Set Similarity (25 分)_22行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given two sets of integers, the similarity of the sets is defined ...

  5. 1063 Set Similarity (25 分) java 题解

    Given two sets of integers, the similarity of the sets is defined to be Nc​/Nt​×100%, where Nc​ is t ...

  6. 【PAT(甲级)】1063 Set Similarity(题目意思)

    Given two sets of integers, the similarity of the sets is defined to be Nc​/Nt​×100%, where Nc​ is t ...

  7. 1063 Set Similarity (25 分)【难度: 一般 / 知识点: STL中set的应用】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805409175420928 可以很容易的写出一个最暴力的写法.可以骗21 ...

  8. PAT A1063——set的常见用法详解

    set 常用函数实例 set是一个内部自动有序且不含重复元素的容器 (1)insert() (2)find()  st.find(*it) 找到返回其迭代器,否者返回st.end() (3)size( ...

  9. 【PAT笔记】C++标准模板库STL(二)——set的用法和示例

    2. set的常见用法详解 set翻译为集合,是一个内部自动有序且不含重复的容器.如果要使用set,需要添加头文件#include <set> 另外还要加上using namespace ...

最新文章

  1. java plc通讯_树莓派+西门子PLC+Aliyun
  2. null?对象?异常?到底应该如何返回错误信息
  3. Looping over the databases on a server
  4. java监理的职责_承担监理业务和监理责任的一方及其合法继承人被称为()。...
  5. --c语言运算符_C按位运算符-能力问题和解答
  6. 爬虫前期知识的储备(二)
  7. Flask 中的蓝图 Blueprint
  8. CentOS6修改/etc/fstab文件造成系统无法启动的问题
  9. 数据库学mysql python_mysql学习(4)python操作数据库
  10. mysql可以用except吗_MYSQL 支持EXCEPT语句吗? 例子里EXCEPT后面的换成NOT IN可以吗? 两个例子错在哪里啊?...
  11. 【学生网页设计作品 】关于HTML公益主题网页设计——谨防电信诈骗网
  12. 关于资产分池ABS等金融衍生品内容来袭
  13. java写文件描述_详解Java中的File文件类以及FileDescriptor文件描述类
  14. 电信猫的无线无法连接服务器,光纤猫连接路由器无法上网怎么办
  15. 极简之SVN使用,入职必备
  16. Python绘制卫星星下点轨迹图和卫星星座图
  17. 3款电脑必装软件,功能强大且免费,打死也舍不得卸载
  18. PyGame|给程序插入背景音乐
  19. javascript弹出一个弹窗
  20. 下一个20年全球开发者将过亿?Tesra超算网络与开发者一起迎接AI时代的到来!

热门文章

  1. 洛谷 P4430 小猴打架
  2. ThinkPHP CURD返回结果参考
  3. linux 下启动jar小程序
  4. 用gnuplot画出c产生数据的波形图
  5. Unofficial Windows Binaries for Python Extension Packages
  6. CUDA程序性能调优
  7. TSS描述符表的作用
  8. 一个不错的shell 脚本教程 入门级
  9. SIFT四部曲之——构建关键点特征描述符
  10. [云炬创业基础笔记]第二章创业者测试12