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 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 <cstdio>
#include <set>
using namespace std;const int N = 51;
set<int> st[N];void compare(int x, int y) {int totalnum = st[y].size();int samenum = 0;for (set<int>::iterator it = st[x].begin(); it != st[x].end(); it++) {if (st[y].find(*it) != st[y].end())samenum++;else totalnum++;}printf("%.1f%\n", samenum*100.0 / totalnum);}int main() {int n,m,x,q,a,b;scanf("%d", &n);for (int i = 1; i <= n; i++) {//这里必须从1开始,因为查询的时候scanf("%d", &m);for (int j = 0; j < m; j++) {scanf("%d", &x);st[i].insert(x);}}scanf("%d", &q);for (int i = 0; i < q; i++) {scanf("%d%d", &a, &b);compare(a, b);}return 0;}

1063 Set Similarity (25 分) set注意查询从1到q所以输入的时候也要从1到n相关推荐

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

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

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

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

  3. 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 ...

  4. 1063. Set Similarity (25)

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

  5. 1063 Set Similarity

    1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be N ...

  6. PTA---航空公司VIP客户查询 (25分)---Stl-Map容器简单使用

    Map是STL的一个关联容器,它提供一对一(也就是一个键一个值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时候,在编程上提供快速通道.map内部自建一颗红黑树(一种非严格意义上的 ...

  7. 7-15(查找) 航空公司VIP客户查询(25 分)

    7-15(查找) 航空公司VIP客户查询(25 分) 不少航空公司都会提供优惠的会员服务,当某顾客飞行里程累积达到一定数量后,可以使用里程积分直接兑换奖励机票或奖励升舱等服务.现给定某航空公司全体会员 ...

  8. 7-15 航空公司VIP客户查询 (25分)(没用stl,哈希链地址法实现)

    7-15 航空公司VIP客户查询 (25分) 不少航空公司都会提供优惠的会员服务,当某顾客飞行里程累积达到一定数量后,可以使用里程积分直接兑换奖励机票或奖励升舱等服务.现给定某航空公司全体会员的飞行记 ...

  9. # 7-45 航空公司VIP客户查询 (25 分)

    7-45 航空公司VIP客户查询 (25 分) 不少航空公司都会提供优惠的会员服务,当某顾客飞行里程累积达到一定数量后,可以使用里程积分直接兑换奖励机票或奖励升舱等服务.现给定某航空公司全体会员的飞行 ...

  10. 7-45 航空公司VIP客户查询 (25 分)

    7-45 航空公司VIP客户查询 (25 分) 不少航空公司都会提供优惠的会员服务,当某顾客飞行里程累积达到一定数量后,可以使用里程积分直接兑换奖励机票或奖励升舱等服务.现给定某航空公司全体会员的飞行 ...

最新文章

  1. 源码编译安装percona-xtrabackup-2.3.2
  2. DL之CNN:利用CNN算法实现对句子分类+进行情感分析(预测句子情感)
  3. woe分析_Python数据分析—apply函数
  4. WIN7与WIN10 安装
  5. Python使用元类约束派生类中必须实现指定的成员
  6. java类加载器正确的是_Java面试题:面向对象,类加载器,JDBC, Spring 基础概念
  7. mac 安装php7.4
  8. 028 kafka面试小节
  9. XZ_iOS iOS13浅色模式/暗黑模式导航栏颜色不自动适配
  10. ZooKeeper 客户端: GUI+命令行两大类(史上最全,值得收藏)
  11. 2021-04-23 - TS型网页视频下载 - 学习/实践
  12. 哲学家就餐问题-中断解决
  13. RuntimeError: mat1 and mat2 shapes cannot be multiplied (192x64 and 4x3)
  14. python人工智能方向入门书籍推荐_python 人工智能 入门要看那些理论书
  15. python制作微信个人二维码怎么做_如何用Python制作微信的好友背景墙?
  16. 【练习】获取新浪搜索中的热搜榜的标题
  17. 利弗莫尔的操作系统到底是怎样的?
  18. android棉花糖,清甜棉花糖:安卓M/Android 6.0上手体验评测
  19. 【操作系统】进程-哲学家进餐问题
  20. 林深时见鹿,海蓝时见鲸

热门文章

  1. Android中实现两次点击返回键退出本程序
  2. *(volatile unsigned long *) 语法
  3. Office 365系列(1)------Office 365邮箱申请及初步配置说明
  4. MySQL基础与操作
  5. linux内核升级到3.4
  6. avue 文字点击 弹窗_目前最好用的文字转语音、视频配音方法,一键合成,智能黑科技...
  7. hadoop api 复制文件_Hadoop核心架构是怎样的?
  8. excel在线_如何把pdf转excel将文档保持原有格式
  9. SpringBoot Maven repackage failed: Unable to find a single main class from the following candidates
  10. SpringBoot整合jsp的使用