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.

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 (<=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.

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<iostream>
#include<algorithm>
#include<set>
using namespace std;
set<int> num[];
int main(){
int N, M, temp, K;
scanf("%d", &N);
for(int i = ; i <= N; i++){
scanf("%d", &M);
for(int j = ; j < M; j++){
scanf("%d", &temp);
num[i].insert(temp);
}
}
scanf("%d", &K);
int s1, s2;
for(int i = ; i < K; i++){
scanf("%d %d", &s1, &s2);
int same = , diff = num[s2].size();
for(set<int> ::iterator it = num[s1].begin(); it != num[s1].end(); it++){
if(num[s2].find(*it) != num[s2].end())
same++;
else diff++;
}
double rate = 1.0 * same / diff * 100.0;
printf("%.1lf%%\n", rate);
}
cin >> N;
return ;
}

总结:

1、set可以用于hash表解决不了的情况,比如键值不是int的情况。

2、printf输出%时,需要输出%%。

1063. Set Similarity的更多相关文章

  1. 1063. Set Similarity (25)

    1063. Set Similarity (25) 时间限制 300 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...

  2. PAT 1063 Set Similarity[比较]

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

  3. PAT 1063. Set Similarity

    1063. Set Similarity 题目大意 给定 n 个集合, k 个询问, 求任意两个集合的并集和合集. 思路 一道裸的考察 STL 中 set 的题, 我居然还用 hash 错过一遍, 用 ...

  4. PAT 甲级 1063 Set Similarity (25 分) (新学,set的使用,printf 输出%,要%%)

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

  5. 1063 Set Similarity——PAT甲级

    1063 Set Similarity Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*10 ...

  6. 【PAT】1063. Set Similarity (25) 待改进

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

  7. PAT 甲级 1063 Set Similarity

    https://pintia.cn/problem-sets/994805342720868352/problems/994805409175420928 Given two sets of inte ...

  8. 1063 Set Similarity (25分)

    Given two sets of integers, the similarity of the sets is defined to be /, where N​c​​ is the number ...

  9. PAT 1063 Set Similarity (25)

    题意:给你n个集合,k次询问,每次询问求两个集合的(交集)/(并集). 思路:k有2000,集合大小有10000.先将每个集合排序,对每个询问分别设两个指针指向两个集合的头.设a[i]为指针1的值,b ...

随机推荐

  1. keycloak 调研资料

    1.https://www.keycloak.org/docs/latest/server_development/index.html 下载keycloak 2.https://gitee.com/ ...

  2. Linux ip forward

    Linux 默认带有 ip forward 功能,只不过因为各种原因,默认的配置把该功能关闭了.本文通过 demo 来演示 Linux 的 ip forward 功能,具体场景为:开启 Linux 的 ...

  3. Git的学习与使用

    Git使用教程 一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN和Git最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自 ...

  4. sublime text3 安装package control 出现问题解决过程记录

    1.安装package control 失败 通过最简单的自动安装 package control 失败(详见package control官网). 报错展示: File "./python ...

  5. uml 图学习记录

    UML类图与类的关系详解   2011-04-21 来源:网络   在画类图的时候,理清类和类之间的关系是重点.类的关系有泛化(Generalization).实现(Realization).依赖(D ...

  6. C. Multi-Subject Competition

    链接 [https://codeforces.com/contest/1082/problem/C] 题意 有n个人,m个科目,每个人都有选的科目si,以及他的能力值ri, 规则是每个科目要么选要么不 ...

  7. linux第三次读书笔记

    第七章:链接 一.编译器驱动程序 编译系统提供的调用预处理器.编译器.汇编器和链接器来构造目标文件的程序. 二.静态链接 三.目标文件 三种形式: 1.可重定位目标文件: 2.可执行目标文件: 3.共 ...

  8. R和python语言如何求平均值,中位数和众数

    均值是通过取数值的总和并除以数据序列中的值的数量来计算. R语言平均值公式: mean(x, trim = 0, na.rm = FALSE, ...)#x - 是输入向量.trim - 用于从排序的 ...

  9. 同步或者重构Activiti Identify用户数据的多种方案比较

    http://www.kafeitu.me/activiti/2012/04/23/synchronize-or-redesign-user-and-role-for-activiti.html 如何 ...

  10. [日常工作]非Windows Server 系统远程经常断以及提高性能的方法

    1. 公司内有不少windows xp windows 7 这样的操作系统的机器在机房里面用来跑自动化脚本或者是其他用处. 经常有人反馈机器过一段时间连不上, 其实这一点是一个非常小的地方 很多机器上 ...