PAT 1063. 集合相似度
原题链接
中等
作者:
YAX_AC
,
2024-11-18 15:57:14
,
所有人可见
,
阅读 2
//shared共享
//Nc the number of distinct common numbers shared by the two sets
//Nt is the total number of distinct numbers in the two sets. Your job is to calculate the
//Nc是两个集合中都存在的不同整数的数量,Nt是两个集合中不同整数的数量。
#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_set>
using namespace std;
const int N = 60;
unordered_set<int> S[N];
int main()
{
int n;
cin>>n;
for (int i = 1; i <= n; i ++ )
{
int cnt;
cin>>cnt;
while(cnt--)
{
int x;
cin>>x;
S[i].insert(x);
}
}
int k;
cin>>k;
while(k--)
{
int a,b;
cin>>a>>b;
int res = 0,sa=0;
for(auto k :S[a])
if(S[b].count(k)) sa++;
res = S[a].size()+S[b].size()-sa;
printf("%.1lf%%\n",(double)sa/res*100);
}
return 0;
}