PAT 1063 Set Similarity[比较]】的更多相关文章

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…
1063. Set Similarity 题目大意 给定 n 个集合, k 个询问, 求任意两个集合的并集和合集. 思路 一道裸的考察 STL 中 set 的题, 我居然还用 hash 错过一遍, 用 vector勉强过了, 最后才发现原来如此简单. 代码 #include <cstdio> #include <set> #include <vector> using namespace std; int main(){ int nSet; scanf("%d…
题意:给你n个集合,k次询问,每次询问求两个集合的(交集)/(并集). 思路:k有2000,集合大小有10000.先将每个集合排序,对每个询问分别设两个指针指向两个集合的头.设a[i]为指针1的值,b[j]为指针2的值.如果a[i]==b[j],交集加一:如果不相同,值较小的指针向后移一位:每次都要去重,并且并集加一. 代码: #include<stdio.h> #include<string.h> #include<algorithm> using namespace…
1063 Set Similarity (25 分)   Given two sets of integers, the similarity of the sets is defined to be /, 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. Yo…
1063 Set Similarity 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…
1063. Set Similarity (25) 时间限制 300 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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…
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…
https://pintia.cn/problem-sets/994805342720868352/problems/994805409175420928 Given two sets of integers, the similarity of the sets is defined to be /, where N​c​​ is the number of distinct common numbers shared by the two sets, and N​t​​ is the tot…
读入之后先排序. 询问的时候可以o(m)效率得到答案. #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<vector> #include<string> #include<stack> #include<map> #include<algorithm> using namespace std; s…
题意:两个整数集合,它们的相似度定义为:nc/nt*100%nc为两个集合都有的整数nt为两个集合一共有的整数注意这里的整数都是各不相同的,即重复的不考虑在内.给出n个整数集合,和k个询问,让你输出每个询问中两个集合的相似度. 因为数值范围在[0,10^9],开不了这么大的数组来标记某个数的出现,所以一开始用了map然而最后一个样例超时了因为题目说了不包含重复的元素,所以想到用set来存储set的大小即为集合不相同的整数个数那么寻找a和b集合相同的元素个数,只需要遍历一下a集合的元素,看是否能在…